How to create a database in PostgreSQL and make it accessible for an application:
postgresql-contrib
package also). Make sure it
is up and running.Switch to postgres
user:
$ sudo su - postgres
Start psql
:
$ psql
Create a user <username>
with password <password>
:
postgres=# CREATE USER <username> WITH PASSWORD '<password>';
Create a database <dbname>
:
postgres=# CREATE DATABASE <dbname> OWNER <username> ENCODING 'utf8';
Connect to the database:
postgres=# \c <dbname>
Activate uuid-ossp
extension:
<dbname>=# CREATE EXTENSION IF NOT EXISTS "uuid-ossp";
\q
to quit.^D
to exit the postgres
user shell./var/lib/pgsql/data/pg_hba.conf
(/etc/postgresql/*/main/pg_hba.conf
in Debian) and add the
following lines to it: # TYPE DATABASE USER ADDRESS METHOD
local <dbname> <username> password
host <dbname> <username> 127.0.0.1/32 password
host <dbname> <username> ::1/128 password
$ sudo systemctl restart postgresql