Six things that surprised me while setting up PostgreSQL on Ubuntu

I learnt MySQL in a coursework, and that is as far as my database experience goes. Then I installed PostgreSQL 18.6 on Ubuntu 26.04 (running under WSL2 on Windows) and wrote a setup guide for MySQL users while I did it. I must say, PostgreSQL surprised me more than once.

This is what tripped me up, so I'm giving you a heads up. A note on sources: I ran every PostgreSQL command below on my own install. I did not run MySQL for this article, so where I describe MySQL's behavior, Just know I checked it against the official MySQL documentation.

1. There is no mysql -u root -p

In MySQL you log in as a named user with a password. On a fresh PostgreSQL install on Ubuntu, you do this instead:

sudo -u postgres psql 

You run psql as the Linux user called postgres, and your prompt changes to postgres=#. The # means you are a superuser.

To work as yourself, create a role that matches your Linux username, plus a database you own:

CREATE ROLE <your-username> WITH LOGIN; CREATE DATABASE practice OWNER <your-username>; 

Now, from the normal terminal, run psql -d practice. It lets you in without asking for a password, and your prompt ends in > instead of #, because you are a regular role.

If you try this before creating the role, you get FATAL: role "<your-username>" does not exist. By default, psql connects as a role with the same name as your Linux user.

2. The same role needs a password in one place and none in another

That password-free login is called peer authentication. On a local Unix socket, PostgreSQL asks the operating system which Linux user is connecting, and trusts that name if a role with the same name exists.

Now connect to the same database over TCP instead, using -h 127.0.0.1 (the -w flag means never prompt for a password):

psql -w -h 127.0.0.1 -d practice 
psql: error: connection to server at "127.0.0.1", port 5432 failed: fe_sendauth: no password supplied 

Same role, same database, different result. The rules live in a file called pg_hba.conf, and PostgreSQL reads them top to bottom and uses the first match. Two of them explain what you just saw:

local all all peer host all all 127.0.0.1/32 scram-sha-256 

Over the socket (local), the Linux username is enough. Over TCP (host), a password is required. Applications, ORMs and GUI tools connect over TCP, so they need the password.

This is different from MySQL, where access rules are stored as 'user'@'host' accounts and changed with SQL. In PostgreSQL, pg_hba.conf decides who may connect and how, and GRANT decides what they can do afterwards.

One more trap: in MySQL, -h localhost uses the socket. In PostgreSQL, -h localhost uses TCP and asks for a password. To use the socket, leave out -h.

3. Roles, not users

PostgreSQL has roles. CREATE USER is just shorthand for CREATE ROLE ... WITH LOGIN, and a role without LOGIN cannot connect at all.

A role's name also does not include where it may connect from, which is what the @'host' part does in MySQL. That is pg_hba.conf's job.

Set the password privately instead of typing it inside the command:

\password <your-username> 

PostgreSQL asks you to type it twice, and nothing shows on screen as you type.

4. Commands that start with a backslash

Inside psql, many everyday tasks are backslash shortcuts, not SQL:

  • \l lists databases (MySQL: SHOW DATABASES;)
  • \dt lists tables (SHOW TABLES;)
  • \d notes describes a table (DESCRIBE notes;)
  • \du lists roles
  • \q quits (exit)

These take no semicolon. SQL statements do. If you forget one, psql does not complain. It waits for more input, and the last-but-one character of the prompt changes from = to -:

postgres=> SELECT current_user postgres-> ; 

Type ; to run it, or \r to clear what you typed.

5. Identity columns say no

MySQL's AUTO_INCREMENT has a modern PostgreSQL equivalent:

CREATE TABLE notes ( id INT GENERATED ALWAYS AS IDENTITY PRIMARY KEY, title TEXT NOT NULL, created_at TIMESTAMPTZ DEFAULT now() ); 

Then try to insert your own ID:

INSERT INTO notes (id, title) VALUES (99, 'manual id'); 
ERROR: cannot insert a non-DEFAULT value into column "id" DETAIL: Column "id" is an identity column defined as GENERATED ALWAYS. HINT: Use OVERRIDING SYSTEM VALUE to override. 

PostgreSQL refuses. According to the MySQL docs, AUTO_INCREMENT accepts a manual value and continues the sequence from the largest one. If you want PostgreSQL to behave more like MySQL, define the column as GENERATED BY DEFAULT AS IDENTITY.

6. "active (exited)" is not a crash

When I checked the service, I saw this and was like, where's my mistake now:

Active: active (exited) since Mon 2026-11-16 01:44:04 WAT Process: 403 ExecStart=/bin/true (code=exited, status=0/SUCCESS) 

It had not. On Ubuntu, postgresql.service is only a wrapper that runs /bin/true and exits, so it always says active (exited). The real server runs as a separate unit for each cluster. To check it properly, use:

pg_lsclusters 
Ver Cluster Port Status Owner Data directory Log file 18 main 5432 online postgres /var/lib/postgresql/18/main /var/log/postgresql/postgresql-18-main.log 

A status of online means the server is running.

What I would tell another MySQL user

  • Login depends on how you connect: socket or TCP.
  • Think in roles, and remember that pg_hba.conf decides who gets in.
  • Learn the backslash commands, and end SQL statements with a semicolon.

The full guide, with every command, its real output and a troubleshooting table, is on GitHub: https://github.com/Alachi24/postgresql-for-mysql-users

If you find a mistake, open an issue on the repository. I would rather fix it than leave it.