Skip to content

Instantly share code, notes, and snippets.

@TopekoX
Created June 2, 2022 16:23
Show Gist options
  • Save TopekoX/ec221b9b7c041ea3073e3c862633f4be to your computer and use it in GitHub Desktop.
Save TopekoX/ec221b9b7c041ea3073e3c862633f4be to your computer and use it in GitHub Desktop.

Create User

CREATE USER jonathan;

Check List User

\du

with password

CREATE USER davide WITH PASSWORD 'jw8s0F4';

with time valid

CREATE USER miriam WITH PASSWORD 'jw8s0F4' VALID UNTIL '2005-01-01';

Create an account where the user can create databases:

CREATE USER manuel WITH PASSWORD 'jw8s0F4' CREATEDB;

Alter User

ALTER USER davide WITH PASSWORD 'hu8jmn3';

Change the expiration date of the user's password:

ALTER USER manuel VALID UNTIL 'Jan 31 2030';

Change a password expiration date, specifying that the password should expire at midday on 4th May 2005 using the time zone which is one hour ahead of UTC:

ALTER USER chris VALID UNTIL 'May 4 12:00:00 2005 +1';

Make a password valid forever:

ALTER USER fred VALID UNTIL 'infinity';

Give a user the ability to create other users and new databases:

ALTER USER miriam CREATEUSER CREATEDB;

Drop User

DROP USER jonathan;

With DB

CREATE DATABASE yourdbname;
CREATE USER youruser WITH ENCRYPTED PASSWORD 'yourpass';
GRANT ALL PRIVILEGES ON DATABASE yourdbname TO youruser;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment