Skip to content

Instantly share code, notes, and snippets.

@akhilome
Last active September 29, 2018 19:59
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save akhilome/667e311ca99a9f702ed0f8b90127b16b to your computer and use it in GitHub Desktop.
Save akhilome/667e311ca99a9f702ed0f8b90127b16b to your computer and use it in GitHub Desktop.
How to install and work with Postgresql 10 via psql shell on Ubuntu

Installing PostgreSQL 10 on Ubuntu

last tested on Xenial Xerus(16.04)

First add the postgresql repo to PC's sources list...

echo 'deb http://apt.postgresql.org/pub/repos/apt/ xenial-pgdg main' | sudo tee -a /etc/apt/sources.list.d/test.list > /dev/null

then ...

wget --quiet -O - https://www.postgresql.org/media/keys/ACCC4CF8.asc | sudo apt-key add -

then ...

sudo apt update

then ....

sudo apt install postgresql-10

To reconfigure postgres client authentication methods

sudo nano /etc/postgresql/10/main/pg_hba.conf

or ...

sudo vi /etc/postgresql/10/main/pg_hba.conf

... if you don't have nano installed and you're a god.

You can change peer to trust or md5, then restart server

sudo service postgresql restart

To Login to psql shell as postgres user

psql -U postgres

To create database

createdb -U postgres database_name

To access database

psql -U postgres database_name

or if already in the psql shell,

\c database_name

Some Handy psql commands

updated frequently (i.e. as I run into more)

  • \l => list available databases in current Postgres server
  • \dt => list all tables in current db
  • \q => exit psql
  • \d table_name => shows details/schema of passed table_name
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment