Difference between revisions of "PostgreSQL"

From Dogtag
Jump to: navigation, search
m (Listing Databases)
m (Connecting to Database)
Line 25: Line 25:
  
 
<pre>
 
<pre>
$ sudo -u postgres psql
+
$ sudo -u postgres psql -d <database>
 
</pre>
 
</pre>
  

Revision as of 16:59, 17 March 2020

Installation

To install PostgreSQL client:

$ dnf install postgresql

To install PostgreSQL server:

$ dnf install postgresql-server

Initializing Database

$ postgresql-setup --initdb --unit postgresql
$ systemctl start postgresql

Connecting to Database

To connect to a local database:

$ sudo -u postgres psql -d <database>

To connect to a remote database:

$ psql postgres://<username>:<password>@<hostname>:<port>/<database>

Managing Users

To list users:

psql> \du

To create a user:

psql> create user <username> with password '<password>';

Managing Databases

To list databases:

psql> \l

To create a database:

psql> create database <datatabase> owner <username>;

Listing Tables

psql> \dt

Describing a Table

psql> \d <name>

See Also