September, 2019
So we installed PostgreSQL on our machine.
Now we want to learn how to setup our installed PostgreSQL.
initdb must be run as the user that will own the server process, therefore it is recommended to create a new user and login with it.
# login as user
sudo -iu [username]
initdb creates a new PostgreSQL database cluster (a collection of databases that are managed by a single server instance).
initdb -D /var/lib/postgres/data
If you get permission denied
, you can find a solutin in the initdb docs
If you don’t know how to start a system service, read this.
Example for Arch:
systemctl start postgresql
If you get some problems, read this.
Now we need a role, that can do some operations.
Don’t forget to be logged in as the user you created before:
# login as user
sudo -iu [username]
Create user:
createuser --interactive
No we need a database, that is owned by our new user
createdb -O [username] [dbname]
We’ve just created a user and a database.
Now we can connect to the database shell:
psql -d [dbname]
psql is a terminal-based front-end to PostgreSQL, you can type in queries, issue them to PostgreSQL, and see the query results.
We will write our first commands to get some data.
Hi! I'm Michael 👋 I'm a Mentor & Educator & Senior Web Developer - I help you to reach your (career) goals.