
sudo pacman -SyuThis command updates your package database and your system.
To install PostgreSQL, use the Pacman package manager:
sudo pacman -S postgresqlThis command will install the PostgreSQL server and client on your system.
Before using PostgreSQL, you need to set up the database cluster, which is a group of databases managed by a PostgreSQL server.
sudo -iu postgres
initdb --locale $LANG -E UTF8 -D '/var/lib/postgres/data'
--locale $LANG: Sets the language settings for the database.
-E UTF8: Makes sure the database uses UTF-8 encoding.
-D '/var/lib/postgres/data': Chooses where the data will be stored.
Now, start the PostgreSQL service and enable it to start on boot automatically:
sudo systemctl start postgresql
sudo systemctl enable postgresql
These commands start the PostgreSQL service, so make sure it starts automatically whenever your system boots.
To manage databases and users, switch to the PostgreSQL user:
sudo -iu postgresCreate a new PostgreSQL user with:
createuser --interactiveYou'll be prompted to enter the username and decide whether the new user should be a superuser.
With your PostgreSQL user set up, you can now create a database:
createdb your-database-nameTo start working with your databases, access the PostgreSQL command-line interface (CLI) with:
psqlOr, connect directly to a specific database:
psql mydatabaseWhen you're done, you can exit the PostgreSQL shell by typing:
\q0
7
0