Setup PostgreSQL on Fedora 27
Installing the Version Contained in Fedora’s Repo
PostgreSQL can be installed with yum, the package system of Fedora.
$ yum install postgresql-server postgresql-contrib
This will install the version contained in Fedora’s repo (currently 9.6.7-1).
Installing a Specified Version
To install a specified repo, find an RPM repo package from https://yum.postgresql.org/repopackages.php.
For example, to install PostgreSQL 9.6:
$ rpm -Uvh [https://download.postgresql.org/pub/repos/yum/9.6/fedora/fedora-27-x86_64/pgdg-fedora96-9.6-4.noarch.rpm](https://download.postgresql.org/pub/repos/yum/9.6/fedora/fedora-27-x86_64/pgdg-fedora96-9.6-4.noarch.rpm)
After yum finish installation, initialize PostgreSQL with
$ postgresql-setup initdb
This creates a new PostgreSQL database cluster.
Start and enable PostgreSQL service:
$ systemctl start postgresql
Creating Roles and Databases
PostgreSQL uses “roles” for authentication, which is similar to Unix users and groups. A Unix user “postgres” will be created upon installation. To log into PostgreSQL with this identity:
$ sudo -i -u postgres
psql uses Unix socket file to connect to the PostgreSQL server by default.
peer is the default authentication method for Unix socket file connections, which looks up the PostgreSQL role that is related to the Unix user name.
After logging into PostgreSQL, use
\q to quit.
With the “postgres” Unix account, you can create PostgreSQL roles and databases. To create a new role:
$ createuser --interactive
You will be asked for the user name and other information about the role to create.
To create a database for the role:
$ createdb <db name>
In order to log into PostgreSQL with your own Unix account directly, you should create a PostgreSQL role and a database that have the same name as your Unix account.
With your own Unix account, log into PostgreSQL with:
This will use the PostgreSQL role and connect to the database that have the same name as your account. To view the connection info, use
\conninfo in the PostgreSQL prompt.
Updating Authentication Method
By default PostgreSQL uses
peer authentication for connections through Unix socket file, and
ident for local TCP/IP connections. This can be modified by editing
The default options are around the end of the file:
# TYPE DATABASE USER ADDRESS METHOD
For example, to force password when logging in through TCP/IP connections, replace
md5. A list of supported authentication methods can be found from https://www.postgresql.org/docs/9.6/static/auth-methods.html.