Skip to content

Instantly share code, notes, and snippets.

@NickMcSweeney
Last active November 15, 2024 22:24
Show Gist options
  • Save NickMcSweeney/3444ce99209ee9bd9393ae6ab48599d8 to your computer and use it in GitHub Desktop.
Save NickMcSweeney/3444ce99209ee9bd9393ae6ab48599d8 to your computer and use it in GitHub Desktop.
Getting postgresql running on Arch Linux

Setup Postgresql

run postgresql with systemctl

Install postgres

latest

sudo pacman -S postgresql

specific version

find version & build from source

Check version

postgres --version

Confirm psql is not running

sudo systemctl status postgresql --> should not be running

Login as the postgres user

Note: always do this any time you are doing any type of admin work on psql

sudo su - postgres

Initialize data directory

Note: default db for psql is /var/lib/postgres/data

initdb --locale en_US.UTF-8 -D /var/lib/postgres/data

Logout of postgres user

exit

Confirm psql is still not running

sudo systemctl status postgresql --> should not be running

Start psql

sudo systemctl start postgresql

Confirm psql is running

sudo systemctl status postgresql --> should be active

Create user

Log into postgres

sudo su - postgres

Create a new user

Note: user can be called anything however if you create a PostgreSQL user with the same name as your Linux username, it allows you to access the PostgreSQL database shell without having to specify a user to login (which makes it quite convenient).

createuser --interactive

  • Enter name of role to add: MY_LINUX_USERNAME
  • Shall the new role be a superuser?: y

Logout of postgres user

exit

Restart psql

sudo systemctl restart postgresql

Confirm psql is running

Note: can see that it was restarted by looking at the timestamp on the Active field

sudo systemctl status postgresql

@H4ppy-04
Copy link

Thank you, but before starting PostgreSQL with systemctl start postgresql, you should initdb -D /var/lib/postgres/data*.

But anyway, thank you!

*source

The guide explicitly states to do this. See the step Initialize data directory.

@JoaoPauloFerrariSantAna
Copy link

JoaoPauloFerrariSantAna commented Jun 24, 2024

Thank you, but before starting PostgreSQL with systemctl start postgresql, you should initdb -D /var/lib/postgres/data*.
But anyway, thank you!
*source

The guide explicitly states to do this. See the step Initialize data directory.

Ops, sorry! I will erase the comment--- sorry for the trouble.

@H4ppy-04
Copy link

Thank you, but before starting PostgreSQL with systemctl start postgresql, you should initdb -D /var/lib/postgres/data*.
But anyway, thank you!
*source

The guide explicitly states to do this. See the step Initialize data directory.

Ops, sorry! I will erase the comment--- sorry for the trouble.

No worries at all 👍

@Phylosius
Copy link

...thank you very much

@manceras
Copy link

manceras commented Aug 6, 2024

thanks!

@ammardevz
Copy link

Ty bro

@adityarai004
Copy link

THANK YOU SOOO MUCH!!!!!!

@rickardhm
Copy link

Exactly what I needed, thank you!

@Overshotkuka
Copy link

Without you, I would never find it, thank you

@kauefontes
Copy link

Such a simple and well written set of instructions, thank you very much, friend!!!

@connortsui20
Copy link

Thank you! I feel like the arch wiki should point to this

@kevdogg
Copy link

kevdogg commented Nov 9, 2024

Is there not a command pg_createcluster on arch linux?

@DoffuXx
Copy link

DoffuXx commented Nov 14, 2024

that was smooth thank you !

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment