I tried the following and it failed
bash-3.2$ pg_ctl restart
pg_ctl: no database directory specified and environment variable PGDATA unset
I am using Macbook Pro
and dont remember the directory where my data is stored and so can't set PGDATA either, is there a way to restart Postgres at all without losing data?
Thank you
`psql` on Terminal To get to the PostgreSQL terminal, open your terminal, start the database services ( brew services start postgresql) , then run psql . Thank you!
psql -c "SELECT 1" -d {dbname} > /dev/null || postgres -D /usr/local/var/postgres >postgres. log 2>&1 & if you want to check and start postgres in one go (handy for automation scripts).
As you want to re-start Postgres I assume the server is already running.
Using the superuser account you can query the location of the data directory through SQL:
select name, setting
from pg_settings
where name = 'data_directory'
With that information you can supply the data directory to the pg_ctl command using the -D
switch (see the manual for details)
If you used brew
you could find the restart(start|stop) instructions by doing a brew info postgresql
Some issues that happen stem from the fact I've seen the plist not load, on OS startup, for some reason. I always forgot what to do and this helped.
on my Postgres 9.2 brew recipe it had:
launchctl unload ~/Library/LaunchAgents/homebrew.mxcl.postgresql.plist
launchctl load ~/Library/LaunchAgents/homebrew.mxcl.postgresql.plist
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With