macos - stop - uninstall postgres mac
How to start PostgreSQL server on Mac OS X? (14)
I had forgotten to run the initdb command.
< /FINAL UPDATE>
by running this command
ps auxwww | grep postgres
I see that postgres is not running
> ps auxwww | grep postgres remcat 1789 0.0 0.0 2434892 480 s000 R+ 11:28PM 0:00.00 grep postgres
this raises the question: How do I start the postgresql server?
>pg_ctl -D /usr/local/var/postgres -l /usr/local/var/postgres/server.log start server starting sh: /usr/local/var/postgres/server.log: No such file or directory
The touch was not successful so I did this instead:
> mkdir /usr/local/var/postgres > vi /usr/local/var/postgres/server.log > ls /usr/local/var/postgres/ server.log
But when I try to start rails server, I still see this:
Is the server running on host "localhost" and accepting TCP/IP connections on port 5432?
> pg_ctl -D /usr/local/var/postgres status pg_ctl: no server running
I found that there WAS NO pg_hba.conf (only pg_hba.conf.sample) so I modified the sample and renamed it (to remover the .sample). Here are the contents:
# IPv4 local connections: host all all 127.0.0.1/32 trust # IPv6 local connections: host all all ::1/128 trust
but I don't understand this:
> pg_ctl -D /usr/local/var/postgres -l /usr/local/var/postgres/server.log start server starting > pg_ctl -D /usr/local/var/postgres status pg_ctl: no server running
sudo find / -name postgresql.conf find: /dev/fd/3: Not a directory find: /dev/fd/4: Not a directory
sudo pg_ctl -D /usr/local/var/postgres -l /usr/local/var/postgres/server.log start Password: pg_ctl: cannot be run as root Please log in (using, e.g., "su") as the (unprivileged) user that will own the server process.
this seems odd:
> egrep 'listen|port' /usr/local/var/postgres/postgresql.conf egrep: /usr/local/var/postgres/postgresql.conf: No such file or directory
though, I did do this:
>sudo find / -name "*postgresql.conf*" find: /dev/fd/3: Not a directory find: /dev/fd/4: Not a directory /usr/local/Cellar/postgresql/9.0.4/share/postgresql/postgresql.conf.sample /usr/share/postgresql/postgresql.conf.sample
so I did this:
egrep 'listen|port' /usr/local/Cellar/postgresql/9.0.4/share/postgresql/postgresql.conf.sample #listen_addresses = 'localhost' # what IP address(es) to listen on; #port = 5432 # (change requires restart) # supported by the operating system: # %r = remote host and port
so I tried this:
> cp /usr/local/Cellar/postgresql/9.0.4/share/postgresql/postgresql.conf.sample /usr/local/Cellar/postgresql/9.0.4/share/postgresql/postgresql.conf > cp /usr/share/postgresql/postgresql.conf.sample /usr/share/postgresql/postgresql.conf
still getting the same "Is the server running?" message.
$ brew upgrade postgres
fixed it for me.
That, of course, will upgrade your postgres version and update/install any dependencies. WARNING: Do this knowing that your postgresql version will likely change. For me, that wasn't a big deal.
If your computer was abruptly restarted
First, you have to delete the file
/usr/local/var/postgres/postmaster.pid Then you can restart the service using one of the many other mentioned methods depending on your install.
You can verify this by looking at the logs of Postgres to see what might be going on:
tail -f /usr/local/var/postgres/server.log
For Mac/OSX, I really like LaunchRocket for this and other background services I used in development.
This site has nice instructions on installation: http://macappstore.org/launchrocket/
This gives you a nice screen in your System Preferences that allows you to launch, reboot, root, launch at login.
For a quick disposable test database you can run the server in the foreground.
Initialize a new postgres database in a new directory
mkdir db initdb db -E utf8 createdb public
Start the server in the foreground (ctrl-C to stop the server)
postgres -d db
In another shell session, connect to the server
psql -d public
For macports, just use the load/unload command and the port name of the running server:
sudo port load postgresql96-server - or - sudo port unload postgresql96-server
so you don't have to remember where the
/Library/LaunchDaemons/org.macports.postgresql96.plist file is located
For test purposes, i think PostgreSQL App is the best option!
Run an App, and the server is up and running. Close the App, and the server goes down.
I had almost the exact same issue, and you cited the initdb command as being the fix. This was also the solution for me, but I didn't see that anyone posted it here, so for those who are looking for it:
initdb /usr/local/var/postgres -E utf8
I have same problem and perform all updates from first post. But after check log file:
I see true cause:
FATAL: data directory "/usr/local/var/postgres" has group or world access DETAIL: Permissions should be u=rwx (0700).
After change permission on this directory
chmod 0700 /usr/local/var/postgres
postgres server has start.
Everytime check log file.
PostgreSQL is integrated in Server.app available through the App Store in Mountain Lion. That means that it is already configured, and you only need to launch it, and then create users and databases.
Tip: Do not start with defining $PGDATA and so on, take file locations as is.
You would have this file: /Library/Server/PostgreSQL/Config/org.postgresql.postgres.plist
sudo serveradmin start postgres
Process started with arguments:
/Applications/Server.app/Contents/ServerRoot/usr/bin/postgres_real -D /Library/Server/PostgreSQL/Data -c listen_addresses=127.0.0.1,::1 -c log_connections=on -c log_directory=/Library/Logs/PostgreSQL -c log_filename=PostgreSQL.log -c log_line_prefix=%t -c log_lock_waits=on -c log_statement=ddl -c logging_collector=on -c unix_socket_directory=/private/var/pgsql_socket -c unix_socket_group=_postgres -c unix_socket_permissions=0770
You can sudo:
sudo -u _postgres psql template1
psql -h localhost -U _postgres postgres
You can find the data directory, version, running status and so forth with
sudo serveradmin fullstatus postgres
The Homebrew package manager includes launchctl plists to start automatically. For more information run
brew info postgres.
pg_ctl -D /usr/local/var/postgres start
pg_ctl -D /usr/local/var/postgres stop
"To have launchd start postgresql now and restart at login:"
brew services start postgresql
What is the result of
pg_ctl -D /usr/local/var/postgres -l /usr/local/var/postgres/server.log start?
What is the result of
pg_ctl -D /usr/local/var/postgres status?
Are there any error messages in the server.log?
Make sure tcp localhost connections are enabled in pg_hba.conf:
# IPv4 local connections: host all all 127.0.0.1/32 trust
Check the listen_addresses and port in postgresql.conf:
egrep 'listen|port' /usr/local/var/postgres/postgresql.conf
#listen_addresses = 'localhost' # what IP address(es) to listen on; #port = 5432 # (change requires restart)
Check the output of the following commands to determine which package manager it was installed with:
brew && brew list|grep postgres fink && fink list|grep postgres port && port installed|grep postgres
To start the postgresql server:
pg_ctl -D /usr/local/var/postgres -l /usr/local/var/postgres/server.log start
to end the postgresql server:
pg_ctl -D /usr/local/var/postgres stop -s -m fast
You can also create an alias via CLI to make it easier:
alias pg-start='pg_ctl -D /usr/local/var/postgres -l /usr/local/var/postgres/server.log start' alias pg-stop='pg_ctl -D /usr/local/var/postgres stop -s -m fast'
With these you can just type "pg-start" to start Postgres and "pg-stop" to shut it down.
Variation on this answer: https://.com/a/13103603/2394728
initdb `brew --prefix`/var/postgres/data -E utf8`
when you install postgresql using homebrew:
brew install postgres
at the end of the output you will see this methods to start server:
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 think this is the best way.
You can add alias into your .profile for convenience.
# remove old database files (If there was any) $rm -rf /usr/local/var/postgres # install the binary $ brew install postgresql # init it $ initdb /usr/local/var/postgres # start the postgres server $ postgres -D /usr/local/var/postgres # create your database $ createdb mydb # Access db. $ psql mydb psql (9.0.1) Type "help" for help.