I only know the basics of using postgres db and have been using it for about a year without any major problems I couldn't get through with the docs or existing stackoverflow questions.
But now I have a problem where I keep getting the following error on my pg db on my mac. I tried to install an updated postgres using brew which installed successful, but I think in the process I created another problem. The error is when trying to start the db:
LOG: database system shutdown was interrupted; last known up at 2015-10-04 11:04:08 EDT
LOG: database system was not properly shut down; automatic recovery in progress
LOG: redo starts at 0/6000090
LOG: record with zero length at 0/6001990
LOG: redo done at 0/6001960
LOG: last completed transaction was at log time 2015-10-04 10:56:33.121103-04
FATAL: could not open directory "pg_logical/snapshots": No such file or directory
LOG: startup process (PID 12905) exited with exit code 1
LOG: aborting startup due to startup process failure
So I followed the instructions here for using pg_resetxlog and then procceeded to try and "REINDEX, dump your database(s), re-initdb, and reload your databases" Per pg documentation for 9.4 with no successful results. Im just going in circles.
I can start over with the db but I'm unable to drop it and start over. If I run dropdb dbname I get
dropdb: could not connect to database template1: could not connect to server: No such file or directory
Is the server running locally and accepting
connections on Unix domain socket "/tmp/.s.PGSQL.5432"?
But I can't start the db because after running
pg_resetxlog -f /usr/local/var/postgres
And getting back "Transaction log reset" I run
pg_ctl start -D /usr/local/var/postgres
And get
pg_ctl: another server might be running; trying to start server anyway
server starting
FATAL: lock file "postmaster.pid" already exists
HINT: Is another postmaster (PID 13114) running in data directory "/usr/local/var/postgres"?
So I ran
ps auxwww | grep postgres
And got
Travis 13127 0.0 0.0 2432772 660 s000 S+ 11:24AM 0:00.00 grep postgres
Travis 13120 0.0 0.0 2468112 604 ?? Ss 11:21AM 0:00.00 postgres: stats collector process
Travis 13119 0.0 0.0 2604776 1444 ?? Ss 11:21AM 0:00.00 postgres: autovacuum launcher process
Travis 13118 0.0 0.0 2604776 732 ?? Ss 11:21AM 0:00.00 postgres: wal writer process
Travis 13117 0.0 0.0 2612968 1776 ?? Ss 11:21AM 0:00.05 postgres: writer process
Travis 13116 0.0 0.0 2604776 756 ?? Ss 11:21AM 0:00.00 postgres: checkpointer process
Travis 13114 0.0 0.2 2604776 14576 ?? S 11:21AM 0:00.02 /usr/local/opt/postgresql/bin/postgres -D /usr/local/var/postgres -r /usr/local/var/postgres/server.log
So I ran
kill 13114
Then
ps auxwww | grep postgres
And got
Travis 13139 0.0 0.0 2432772 652 s000 S+ 11:25AM 0:00.00 grep postgres
Of course at this point if I try to start the db again I go in the same circle.
Now if I run
pg_resetxlog -f /usr/local/var/postgres
followed by
psql template1
And try to drop the db nothing happens.
It's a db for a rails project. So if I run
rake db:drop
I get another
PG::InternalError: ERROR: checkpoint request failed
It also says there is a hint in the server log which I checked with
live:
tail -f /usr/local/var/postgres/server.log
Or:
tail /usr/local/var/postgres/server.log
And get
ERROR: could not open directory "pg_logical/snapshots": No such file or directory
ERROR: could not open directory "pg_logical/snapshots": No such file or directory
ERROR: could not open directory "pg_logical/snapshots": No such file or directory
ERROR: could not open directory "pg_logical/snapshots": No such file or directory
ERROR: could not open directory "pg_logical/snapshots": No such file or directory
ERROR: could not open directory "pg_logical/snapshots": No such file or directory
ERROR: could not open directory "pg_logical/snapshots": No such file or directory
ERROR: could not open directory "pg_logical/snapshots": No such file or directory
ERROR: could not open directory "pg_logical/snapshots": No such file or directory
ERROR: could not open directory "pg_logical/snapshots": No such file or directory
I'm not sure how to fix that or why it dosent exist anymore in the first place. Search results returned this but there was no solution showing the full path for manually creating the directory
At this point I'm so confused I think I'm making things worse.
I checked other db on my system and see I have the same problem for all databases on my machine now. Plus I always have 1 grep postgres pid running that i can't stop with kill 13498 or by restarting my mac.
How do i fix this without loosing all databases on my machine?
Brew info postgres shows:
postgresql: stable 9.4.4 (bottled), devel 9.5alpha2
Object-relational database system
https://www.postgresql.org/
Conflicts with: postgres-xc
/usr/local/Cellar/postgresql/9.4.1_1 (2996 files, 40M)
Poured from bottle
/usr/local/Cellar/postgresql/9.4.4 (3014 files, 40M) *
Poured from bottle
From: https://github.com/Homebrew/homebrew/blob/master/Library/Formula/postgresql.rb
==> Dependencies
Required: openssl ✔, readline ✔
==> Options
--32-bit
Build 32-bit only
--with-dtrace
Build with DTrace support
--with-python
Build with python support
--without-perl
Build without Perl support
--without-tcl
Build without Tcl support
--devel
Install development version 9.5alpha2
==> Caveats
If builds of PostgreSQL 9 are failing and you have version 8.x installed,
you may need to remove the previous version first. See:
https://github.com/Homebrew/homebrew/issues/2510
To migrate existing data from a previous major version (pre-9.4) of PostgreSQL, see:
https://www.postgresql.org/docs/9.4/static/upgrading.html
To have launchd start postgresql at login:
ln -sfv /usr/local/opt/postgresql/*.plist ~/Library/LaunchAgents
Then to load postgresql now:
launchctl load ~/Library/LaunchAgents/homebrew.mxcl.postgresql.plist
Or, if you don't want/need launchctl, you can just run:
postgres -D /usr/local/var/postgres
I'm running yosemite 10.10.5