go to  ForumEasy.com   
JavaPro
Home » Archive » Message


[Email To Friend][View in Live Context][prev topic « prev post | next post » next topic]
  Use database Postgre
 
Subject: Use database Postgre
Author: Linux
In response to: Connect to PostgreSQL database server
Posted on: 09/05/2017 12:06:05 AM

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



 

> On 09/04/2017 11:46:43 PM Linux wrote:

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






References:

 


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