PostgreSQL

From Dogtag
Revision as of 22:01, 13 January 2020 by Edewata (talk | contribs) (Listing Databases)

Jump to: navigation, search

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