go to  ForumEasy.com   
JavaPro
Home » Archive » Message


[Email To Friend][View in Live Context][prev topic « prev post | next post » next topic]
  Connect to PostgreSQL database server
 
Subject: Connect to PostgreSQL database server
Author: Linux
In response to: Check to see if it's running
Posted on: 09/04/2017 11:46:43 PM

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:~$ 



 

> On 09/04/2017 11:25:13 PM Linux wrote:

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     







References:

 


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