Skip to content

Instantly share code, notes, and snippets.

@silviud
Created August 31, 2021 14:00
Show Gist options
  • Save silviud/dd2caaf018c4d2816b8d82397dd3e768 to your computer and use it in GitHub Desktop.
Save silviud/dd2caaf018c4d2816b8d82397dd3e768 to your computer and use it in GitHub Desktop.
Create postgresql role and database from shell
# create password - note the md5 is the prefix and the value is user + password
$ U=testpg; P=testpg; echo -n md5; echo -n $P$U | md5sum | cut -d' ' -f1
$ md54bb01023735acf990f528fe961df8140
# connect to pg
$ psql
postgres=# CREATE ROLE testpg NOSUPERUSER NOCREATEDB NOCREATEROLE NOINHERIT LOGIN PASSWORD 'md54bb01023735acf990f528fe961df8140';
postgres=# CREATE DATABASE testpgdb OWNER testpg;
^D
# at this point you can connect to the database `testpgdb` such so
$ psql -U testpg -d testpgdb -h YOURHOST -W
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment