[Insights](/insights/) / [Core Engineering Intelligence](/insights/core_engineering_intelligence/)

# Install PostgreSQL and create a database and user from the command line

Install PostgreSQL on Ubuntu or WSL, then create a database owned by its own user in two SQL commands, and connect with one URL.

![Ivan Borshchov](https://static.devforth.io/adminusers/avatars/2026/48db9847-d461-40cd-b344-f2bd7b0d98ca-avatar_ivan@devforth.io_f4ce9df9-8363-4314-9345-28753c76a386.jpeg)

Ivan Borshchov

CEO & System Architect @ DevForth

Dec 3, 2026

![Install PostgreSQL and create a database and user from the command line](https://static.devforth.io/posts/logo-svg/2026/4289b5ee-f719-4e22-8f1d-519f5fa1fa11-logo-preview-new.svg)

![Install PostgreSQL and create a database and user from the command line](https://static.devforth.io/posts/logo-svg/2026/4289b5ee-f719-4e22-8f1d-519f5fa1fa11-logo-preview-new.svg)

PostgreSQL is a database: a very tidy cupboard where your app keeps its data. Here is the shortest way to get one on Ubuntu (or Ubuntu inside WSL on Windows) and give your app its own shelf.

**Install it**

```bash
sudo apt update
sudo apt install postgresql
```

Ubuntu starts the service for you. On WSL without systemd, start it with `sudo service postgresql start`.

**Open the database console**

Postgres creates a system user called `postgres`, which is the boss of the database. Borrow it to open `psql`:

```bash
sudo -u postgres psql
```

This step needs no extra password.

**Create a user and a database**

```sql
CREATE USER myapp WITH PASSWORD 'change-me';
CREATE DATABASE myapp OWNER myapp;
```

The important part is making the user the _owner_. Older guides run `GRANT ALL PRIVILEGES ON DATABASE ...` followed by a list of grants on tables and sequences. Since PostgreSQL 15 that is no longer enough to create tables in the `public` schema, and the app fails with "permission denied". An owner can do anything inside its own database, which is usually exactly what an app needs.

Type `\q` to leave.

**Check that it works**

```bash
psql "postgresql://myapp:change-me@localhost:5432/myapp" -c "select 1"
```

Most frameworks and ORMs expect this same string in `DATABASE_URL`.

**Two small safety habits**

-   Use a long random password instead of `change-me`.
-   Keep Postgres listening on localhost, which is the default. If another server has to connect, open the port to that server only.

In short: install it, open `sudo -u postgres psql`, create a user, create a database owned by that user, and connect with one URL.

## Get your project quote

Free result within 48-72 hours

[

Get a quote

](/estimation-request/)[

Talk to our engineers

](https://talk.devforth.io/book/30-minute-meeting)

[

Back to insights

](/insights/)

[](https://www.linkedin.com/sharing/share-offsite/?url=https%3A%2F%2Fdevforth.io%2Finsights%2Finstall-postgresql-and-create-a-database-and-user-from-the-command-line%2F)[](https://bsky.app/intent/compose?text=Install%20PostgreSQL%20and%20create%20a%20database%20and%20user%20from%20the%20command%20line%0A%0Ahttps%3A%2F%2Fdevforth.io%2Finsights%2Finstall-postgresql-and-create-a-database-and-user-from-the-command-line%2F)[](https://x.com/intent/tweet?text=Install%20PostgreSQL%20and%20create%20a%20database%20and%20user%20from%20the%20command%20line%20by%20%40ivanborshchov%0A%0Ahttps%3A%2F%2Fdevforth.io%2Finsights%2Finstall-postgresql-and-create-a-database-and-user-from-the-command-line%2F)

## Related insights

[

![How to create an AWS account and keep it safe](https://static.devforth.io/posts/logo-svg/2026/9846537f-161d-4fbc-b845-786ab85ed79c-logo-preview-new.svg)

Core Engineering Intelligence Dec 3, 2026

## How to create an AWS account and keep it safe

Create an AWS account the safe way. Protect the root user with MFA, set a budget alert and use a separate short-lived login for daily work.

](/insights/how-to-create-an-aws-account-and-keep-it-safe/)[

![Painterro, a simple JS paint plugin for your website](https://static.devforth.io/posts/logo-svg/2026/c453add8-a6e5-4a6d-817d-fe94f866725c-logo-preview-new.svg)

Core Engineering Intelligence Dec 3, 2026

## Painterro, a simple JS paint plugin for your website

Painterro is a small open-source image editor for the browser. Paste a screenshot, crop it, add arrows and text, and save it to your own backend.

](/insights/painterro-a-simple-js-paint-plugin-for-your-website/)[

![Serverless Framework with AWS, an easy practical start](https://static.devforth.io/posts/logo-svg/2026/a0847920-647d-44f3-95f0-1ae88ebb53e2-logo-preview-new.svg)

Core Engineering Intelligence Dec 3, 2026

## Serverless Framework with AWS, an easy practical start

What serverless means, how Serverless Framework deploys a function to AWS Lambda in one command, and what to know about its v4 license first.

](/insights/serverless-framework-with-aws-an-easy-practical-start/)
