go to  ForumEasy.com   
JavaPro  
 
 
   Home  |  MyForum  |  FAQ  |  Archive    You are not logged in. [Login] or [Register]  
Forum Home » Java Deploying » How to Install PostgreSQL on Ubuntu 16.04 LTS
Email To Friend  |   Set Alert To This Topic Rewarding Points Availabe: 0 (What's this) New Topic  |   Post Reply
Author Topic: How to Install PostgreSQL on Ubuntu 16.04 LTS
Linux
member
offline   
 
posts: 120
joined: 01/24/2011
from: San Jose, CA
  posted on: 09/04/2017 11:17:48 PM    Edit  |   Quote  |   Report 
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

 Profile | Reply Points Earned: 0
Linux
member
offline   
 
posts: 120
joined: 01/24/2011
from: San Jose, CA
  posted on: 09/04/2017 11:19:17 PM    Edit  |   Quote  |   Report 
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:
       listen_addresses = '*'



Step 5) Restart Postgres -- optional

-- adminstrator@ubuntu:~$ sudo /etc/init.d/postgresql restart

 Profile | Reply Points Earned: 0
Linux
member
offline   
 
posts: 120
joined: 01/24/2011
from: San Jose, CA
  posted on: 09/04/2017 11:25:13 PM    Edit  |   Quote  |   Report 
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     



 Profile | Reply Points Earned: 0
Linux
member
offline   
 
posts: 120
joined: 01/24/2011
from: San Jose, CA
  posted on: 09/04/2017 11:46:43 PM    Edit  |   Quote  |   Report 
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:~$ 


 Profile | Reply Points Earned: 0
Linux
member
offline   
 
posts: 120
joined: 01/24/2011
from: San Jose, CA
  posted on: 09/05/2017 12:06:05 AM    Edit  |   Quote  |   Report 
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


 Profile | Reply Points Earned: 0

 
Powered by ForumEasy © 2003-2005, All Rights Reserved. | Privacy Policy | Terms of Use
 
Get your own forum today. It's easy and free.