Skip to content

Instantly share code, notes, and snippets.

@shotaK
Last active November 27, 2015 20:20
Show Gist options
  • Save shotaK/80b1d9e6fb98a3450042 to your computer and use it in GitHub Desktop.
Save shotaK/80b1d9e6fb98a3450042 to your computer and use it in GitHub Desktop.
PostgreSQL
// create user shota with password 1111, when logged in certain DB
CREATE USER shota WITH SUPERUSER LOGIN PASSWORD '1111';
// grant all privileges to specific user
grant all privileges on database db_name to someuser;
Default postgres user:
username: postgres
password: postgres
// Insert data with primary + serial key
INSERT INTO press(
id, sort_id, logo, description, link, link_text)
VALUES (default, 3, 'fodors.png', 'Travel Trend: Eat Like Locals, With Locals.', 'http://www.fodors.com/', 'Fodors');
// list databases
\l
// list tables
\d
// list specific table content
\d tablename
// list roles
\du
// list commands
\help
// select all the data from table, IMPORTANT: dont forget semicolon
SELECT * FROM articles;
nano /var/lib/pgsql/data/pg_hba.conf
// start postgres service
sudo systemctl start postgresql.service
// view postgres service status
systemctl status postgresql.service
// login to postgres database server
su - postgres
// create db posttestdb under the owner of shota
createdb -O shota posttestdb
// Create DB called testDB
createdb testDB
// login to testDB database
psql testDB
// make user SUPERUSER
ALTER ROLE <user_name> SUPERUSER;
// allow user create DB
ALTER ROLE clikhome CREATEDB;
// Other options
SUPERUSER
NOSUPERUSER
CREATEDB
NOCREATEDB
CREATEROLE
NOCREATEROLE
CREATEUSER
NOCREATEUSER
INHERIT
NOINHERIT
LOGIN
NOLOGIN
REPLICATION
NOREPLICATION
CONNECTION LIMIT connlimit
PASSWORD password
ENCRYPTED
UNENCRYPTED
VALID UNTIL 'timestamp'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment