Use \l or \l+ in psql to show all databases in the current PostgreSQL server. Use the SELECT statement to query data from the pg_database to get all databases.
basically just type "systemctl status postgresql-xx" where xx is the version of your PostgreSQL instance. ex: systemctl status posgresql-10. 2. There can be situations where you don't remember which version of postgres you installed and checking the service status just doesn't work.
The simplest way to to check running processes:
ps auxwww | grep postgres
And look for a command that looks something like this (your version may not be 8.3):
/Library/PostgreSQL/8.3/bin/postgres -D /Library/PostgreSQL/8.3/data
To start the server, execute something like this:
/Library/PostgreSQL/8.3/bin/pg_ctl start -D /Library/PostgreSQL/8.3/data -l postgres.log
You can run the following command to determine if postgress is running:
$ pg_ctl status
You'll also want to set the PGDATA
environment variable.
Here's what I have in my ~/.bashrc
file for postgres:
export PGDATA='/usr/local/var/postgres'
export PGHOST=localhost
alias start-pg='pg_ctl -l $PGDATA/server.log start'
alias stop-pg='pg_ctl stop -m fast'
alias show-pg-status='pg_ctl status'
alias restart-pg='pg_ctl reload'
To get them to take effect, remember to source it like so:
$ . ~/.bashrc
Now, try it and you should get something like this:
$ show-pg-status
pg_ctl: server is running (PID: 11030)
/usr/local/Cellar/postgresql/9.2.4/bin/postgres
You probably did not init postgres.
If you installed using HomeBrew, the init must be run before anything else becomes usable.
To see the instructions, run brew info postgres
# Create/Upgrade a Database
If this is your first install, create a database with:
initdb /usr/local/var/postgres -E utf8
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:
pg_ctl -D /usr/local/var/postgres -l /usr/local/var/postgres/server.log start
Once you have run that, it should say something like:
Success. You can now start the database server using:
postgres -D /usr/local/var/postgres or pg_ctl -D /usr/local/var/postgres -l logfile start
If you are still having issues, check your firewall. If you use a good one like HandsOff! and it was configured to block traffic, then your page will not see the database.
As of PostgreSQL 9.3, you can use the command pg_isready
to determine the connection status of a PostgreSQL server.
From the docs:
pg_isready returns 0 to the shell if the server is accepting connections normally, 1 if the server is rejecting connections (for example during startup), 2 if there was no response to the connection attempt, and 3 if no attempt was made (for example due to invalid parameters).
It depends on where your postgresql server is installed. You use the pg_ctl to manually start the server like below.
pg_ctl -D /usr/local/var/postgres -l /usr/local/var/postgres/server.log start
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