DEV Community

Pheak Pheasa
Pheak Pheasa

Posted on

ubuntu server create database and create new user with password for there database in postgresql.

To create a new database and a new user with a password in PostgreSQL on Ubuntu Server, you can follow these steps:

  1. Install PostgreSQL if it's not already installed:
sudo apt update
sudo apt install postgresql postgresql-contrib
  1. Switch to the postgres user:
sudo -i -u postgres
  1. Access the PostgreSQL prompt:
psql
  1. Create a new database:
CREATE DATABASE mydatabase;
  1. Create a new user and set a password:
CREATE USER myuser WITH PASSWORD 'mypassword';

Replace myuser with your desired username and mypassword with your desired password.

  1. Grant privileges on the database to the user:
GRANT ALL PRIVILEGES ON DATABASE mydatabase TO myuser;
  1. Exit the PostgreSQL prompt:
\q
  1. Exit from the postgres user:
exit

That's it! You've now created a new database and a new user with a password in PostgreSQL on your Ubuntu Server.

Image of Timescale

🚀 pgai Vectorizer: SQLAlchemy and LiteLLM Make Vector Search Simple

We built pgai Vectorizer to simplify embedding management for AI applications—without needing a separate database or complex infrastructure. Since launch, developers have created over 3,000 vectorizers on Timescale Cloud, with many more self-hosted.

Read full post →

Top comments (0)

Billboard image

The Next Generation Developer Platform

Coherence is the first Platform-as-a-Service you can control. Unlike "black-box" platforms that are opinionated about the infra you can deploy, Coherence is powered by CNC, the open-source IaC framework, which offers limitless customization.

Learn more