What do you think? Discuss, post comments, or ask questions at the end of this article [More about me]

Below are several commands for postgresql that I keep forgetting.  For reference.

Install postgresql (on Ubuntu/Debian)

sudo apt-get install postgresql

Switching to user postgress (and optionally starting psql)

sudo -i -u postgres
psql

To exit psql type \q

Set postgres user password

sudo -u postgres psql postgres
\password postgres

Starting/stopping postgresql services

sudo service postgresql start
sudo service postgresql stop

Create user and change password

sudo -i -u postgres
createuser --interactive
psql
ALTER USER user_name WITH PASSWORD 'new_password';

Create database

CREATE DATABASE dbname OWNER owner;

I've had trouble with this not actually working.  What did work though was:

sudo -i -u postgres
createdb <DATABASE>

Drop database

DROP DATABASE dbname

or

sudo -i -u postgres
dropdb <DATABASE>

References

  1. https://www.digitalocean.com/community/tutorials/how-to-install-and-use-postgresql-on-ubuntu-16-04
  2. http://suite.opengeo.org/docs/latest/dataadmin/pgGettingStarted/firstconnect.html
  3. http://suite.opengeo.org/docs/latest/dataadmin/pgGettingStarted/firstconnect.html