Last active
November 27, 2015 20:20
-
-
Save shotaK/80b1d9e6fb98a3450042 to your computer and use it in GitHub Desktop.
PostgreSQL
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Default postgres user: | |
username: postgres | |
password: postgres |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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'); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
nano /var/lib/pgsql/data/pg_hba.conf |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// start postgres service | |
sudo systemctl start postgresql.service | |
// view postgres service status | |
systemctl status postgresql.service |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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 | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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