Author |
Topic: How to Install PostgreSQL on Ubuntu 16.04 LTS |
|
Linux member offline |
|
posts: |
120 |
joined: |
01/24/2011 |
from: |
San Jose, CA |
|
|
|
|
|
How to Install PostgreSQL on Ubuntu 16.04 LTS |
Step 1) Install Postgres key -- adminstrator@ubuntu:~$ wget --quiet -O - https://www.postgresql.org/media/keys/ACCC4CF8.asc | sudo apt-key add -
Step 2) Add APT repository -- adminstrator@ubuntu:~$ sudo sh -c 'echo deb http://apt.postgresql.org/pub/repos/apt/ trusty-pgdg main > /etc/apt/sources.list.d/postgresql.list'
Step 3) Install Postgres -- adminstrator@ubuntu:~$ sudo apt-get update -- adminstrator@ubuntu:~$ sudo apt-get install postgresql postgresql-contrib
|
|
|
|
|
|
|
Linux member offline |
|
posts: |
120 |
joined: |
01/24/2011 |
from: |
San Jose, CA |
|
|
|
|
|
Configure Postgres |
Step 4) Configure Postgres to allow reomte access -- optional
-- adminstrator@ubuntu:~$ sudo nano /etc/postgresql/9.6/main/postgresql.conf
Change:
#listen_addresses = 'localhost'
to:
Step 5) Restart Postgres -- optional
-- adminstrator@ubuntu:~$ sudo /etc/init.d/postgresql restart
|
|
|
|
|
|
|
Linux member offline |
|
posts: |
120 |
joined: |
01/24/2011 |
from: |
San Jose, CA |
|
|
|
|
|
Check to see if it's running |
PostgreSQL database server runs on default port 5432.
You can check it via:
administrator@ubuntu:~$ netstat -tuln | grep 5432
tcp 0 0 127.0.0.1:5432 0.0.0.0:* LISTEN
|
|
|
|
|
|
|
Linux member offline |
|
posts: |
120 |
joined: |
01/24/2011 |
from: |
San Jose, CA |
|
|
|
|
|
Connect to PostgreSQL database server |
Once the PostgreSQL database server is installed, the system has automatically created the following:
postgre -- the default database postgre -- the default user and system account
You can first log into shell as user account 'postgres'
administrator@ubuntu:~$ sudo su - postgres
Then connect to database server via client script 'psql'
postgres@ubuntu:~$ psql
psql (9.6.5, server 9.3.19)
Type "help" for help.
postgres=# \conninfo
You are connected to database "postgres" as user "postgres" via socket in "/var/run/postgresql" at port "5432".
postgres=# \q
postgres@ubuntu:~$ exit
logout
administrator@ubuntu:~$
Alternatively, you can connect to database 'postgres' with user 'postgres', set password and then show connection information
administrator@ubuntu:~$ sudo -u postgres psql postgres
psql (9.6.5, server 9.3.19)
Type "help" for help.
postgres=# \password
Enter new password:
Enter it again:
postgres=# \conninfo
You are connected to database "postgres" as user "postgres" via socket in "/var/run/postgresql" at port "5432".
postgres=# \q
administrator@ubuntu:~$
In general, you can connect to a database with user via
psql -h [localhost|server.domain.org] database user
administrator@ubuntu:~$ psql -h localhost -p 5432 -U postgres postgres
Password for user postgres:
psql (9.6.5, server 9.3.19)
SSL connection (protocol: TLSv1.2, cipher: DHE-RSA-AES256-GCM-SHA384, bits: 256, compression: off)
Type "help" for help.
postgres=# \conninfo
You are connected to database "postgres" as user "postgres" on host "localhost" at port "5432".
SSL connection (protocol: TLSv1.2, cipher: DHE-RSA-AES256-GCM-SHA384, bits: 256, compression: off)
postgres=# \q
administrator@ubuntu:~$
|
|
|
|
|
|
|
Linux member offline |
|
posts: |
120 |
joined: |
01/24/2011 |
from: |
San Jose, CA |
|
|
|
|
|
Use database Postgre |
Create a user
sudo -u postgres createuser canvas --no-createdb --no-superuser --no-createrole --pwprompt
Create a database
sudo -u postgres createdb canvas_production --owner=canvas
|
|
|
|
|
|
|
|