Skip to content
Menu
vernon.wenberg.net
vernon.wenberg.net
February 19, 2024February 19, 2024

Create database and add user in PostgreSQL

# postgres psql
"root" execution of the PostgreSQL server is not permitted.
The server must be started under an unprivileged user ID to prevent
possible system security compromise.  See the documentation for
more information on how to properly start the server.

## You cannot be root to use these commands, so su to postgres user
# su - postgres

## Create user named "testing"
postgres@f8087f90456e:~$ createuser testing

## Create database named "testing"
postgres@f8087f90456e:~$ createdb testing

## Create password  "secretpassword" for user testing.
postgres@f8087f90456e:~$ psql -c "alter user miniflux with encrypted password 'secretpassword';"
ALTER ROLE

## Grant permissions to database testing to user testing
postgres@f8087f90456e:~$ psql -c "grant all privileges on database testing to testing;"
GRANT

## Test it out
postgres@f8087f90456e:~$ psql --host=localhost --dbname=testing --username=testing
psql (14.11 (Debian 14.11-1.pgdg120+2))
Type "help" for help.

testing=>

Share this:

  • Click to share on X (Opens in new window) X
  • Click to share on Facebook (Opens in new window) Facebook
  • Click to print (Opens in new window) Print
  • Click to share on Pocket (Opens in new window) Pocket
  • Click to share on Reddit (Opens in new window) Reddit
  • Click to share on LinkedIn (Opens in new window) LinkedIn

Like this:

Like Loading...

Related

Disclaimer

These posts are notes for me. These are not guides and you should not use these instructions as step-by-step instructions without knowing what they do.

Recent Posts

  • HPE Aruba-CX Notes
  • Docker Reference
  • Useful Commands for Windows Subsystem for Linux
  • FortiManager Local-In Policy
  • Mount Google Drive in Linux using rclone

Mastodon

  1. Loading Mastodon feed...

©2025 vernon.wenberg.net | Powered by WordPress and Superb Themes!
%d