Difference between revisions of "PostgreSQL"

From Dogtag
Jump to: navigation, search
m (Listing Tables)
m (Listing Databases)
(One intermediate revision by the same user not shown)
Line 34: Line 34:
 
</pre>
 
</pre>
  
= Listing Databases =
+
= Managing Users =
 +
 
 +
To list users:
 +
 
 +
<pre>
 +
psql> \du
 +
</pre>
 +
 
 +
To create a user:
 +
 
 +
<pre>
 +
psql> create user <username> with password '<password>';
 +
</pre>
 +
 
 +
= Managing Databases =
 +
 
 +
To list databases:
  
 
<pre>
 
<pre>
 
psql> \l
 
psql> \l
 +
</pre>
 +
 +
To create a database:
 +
 +
<pre>
 +
psql> create database <datatabase> owner <username>;
 
</pre>
 
</pre>
  

Revision as of 22:01, 13 January 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

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