DEV Community

Alfredo Fernandez
Alfredo Fernandez

Posted on

2 2

# Create user with all privileges in PSQL and add to db

Check psql if is installed psql --version if you don't have installed then install from official page when installed make sure can see something like this

psql (PostgreSQL) 14.2 (Ubuntu 14.2-1.pgdg20.04+1+b1)
Enter fullscreen mode Exit fullscreen mode

check status of psql sudo service postgresql status look like this

● postgresql.service - PostgreSQL RDBMS
     Loaded: loaded (/lib/systemd/system/postgresql.service; enabled; vendor preset: enabled)
     Active: active (exited) since Thu 2022-04-14 17:20:08 -04; 3s ago
    Process: 38001 ExecStart=/bin/true (code=exited, status=0/SUCCESS)
   Main PID: 38001 (code=exited, status=0/SUCCESS)

abr 14 17:20:08 alfredo systemd[1]: Starting PostgreSQL RDBMS...
abr 14 17:20:08 alfredo systemd[1]: Finished PostgreSQL RDBMS.

Enter fullscreen mode Exit fullscreen mode

If service psql is inactive only need sudo service postgresql start

Run this command for create user

sudo -u postgres createuser testuser
# For crete db
sudo -u postgres createdb testdb
Enter fullscreen mode Exit fullscreen mode

Now we make setting for nice work with that user and the database
First enter to psql

sudo -u postgres psql
Enter fullscreen mode Exit fullscreen mode

For see all user list you can run \du
when see all user list we cannot see any roles even doesn't exist password for this user , we need add some privileges inside db (postgres)

ALTER USER testuser with encrypted password 'secret';
# If this command run success, message look like this
# ALTER ROLE
grant all privileges on database testdb to testuser;
# GRANT
Enter fullscreen mode Exit fullscreen mode

when list again with \l the database has attach to new user

Image of AssemblyAI

Automatic Speech Recognition with AssemblyAI

Experience near-human accuracy, low-latency performance, and advanced Speech AI capabilities with AssemblyAI's Speech-to-Text API. Sign up today and get $50 in API credit. No credit card required.

Try the API

Top comments (0)

Billboard image

Try REST API Generation for MS SQL Server.

DevOps for Private APIs. With DreamFactory API Generation, you get:

  • Auto-generated live APIs mapped from database schema
  • Interactive Swagger API documentation
  • Scripting engine to customize your API
  • Built-in role-based access control

Learn more

👋 Kindness is contagious

Engage with a sea of insights in this enlightening article, highly esteemed within the encouraging DEV Community. Programmers of every skill level are invited to participate and enrich our shared knowledge.

A simple "thank you" can uplift someone's spirits. Express your appreciation in the comments section!

On DEV, sharing knowledge smooths our journey and strengthens our community bonds. Found this useful? A brief thank you to the author can mean a lot.

Okay