Site Tools


quickref:postgres

This is an old revision of the document!


PosgreSQL QuickRef

PostgreSQL quick reference.

Create Role & DB

CREATE DATABASE <dbname>;
CREATE ROLE <rolename>;
ALTER USER backend WITH PASSWORD '<password>';
ALTER USER backend WITH LOGIN;
ALTER DATABASE <dbname> OWNER TO <rolename>;
GRANT ALL PRIVILEGES ON DATABASE <dbname> TO <rolename>;

Reset Serial Count

-- Reset sequence
ALTER SEQUENCE seq RESTART WITH 1;
 
-- update column to reference sequence
-- (not needed if the column in question is already
-- referenced by the sequence)
UPDATE t SET idcolumn=NEXTVAL('seq');
quickref/postgres.1762265793.txt.gz · Last modified: by theorytoe