lobo_tuerto's notes
for greatly improving DX
Blog
Notes
About

Install PostgreSQL in Linux

The big elephant in the room, the world's most advanced open source relational database.

📅Date08 March 2018Updated28 August 2021
🏷️
devlinuxpostgresql

Installation process

Setting up PostgreSQL in Manjaro Linux is very easy.

Just follow these steps and you’ll have a working installation in no time.

Install the postgresql package:

sudo pacman -S postgresql postgis

Switch to the postgres user account and initialize the database cluster:

sudo su postgres -l # or sudo -u postgres -i
initdb --locale $LANG -E UTF8 -D '/var/lib/postgres/data/'
exit

Options for initdb are as follows:

  • --locale is the one defined in /etc/locale.conf.
  • -E is the default encoding for new databases.
  • -D is the default location for storing the database cluster.

Now, start and enable the postgresql.service:

sudo systemctl enable --now postgresql.service

You can check PostgreSQL’s version with:

psql --version
# psql (PostgreSQL) 13.3

Create a DB user for local development or deployment

sudo su postgres -c psql
CREATE USER deployer WITH PASSWORD 'eldeployerloco';
ALTER ROLE deployer WITH CREATEDB;
\q

On Phoenix you’d use this in config/dev.exs like this:

# Configure your database
config :my_app, MyApp.Repo,
  username: "deployer",
  password: "eldeployerloco",
  database: "my_app_dev",
  hostname: "localhost",
  show_sensitive_data_on_connection_error: true,
  pool_size: 10

That’s it!


Got comments or feedback?
Follow me on
rev-7175614