Last active
January 4, 2016 17:08
-
-
Save doole/8651520 to your computer and use it in GitHub Desktop.
Simple user/database setup for 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
-- | |
-- Reset auto increment | |
-- | |
ALTER SEQUENCE {table}_{column}_seq RESTART WITH 1; | |
-- | |
TRUNCATE TABLE table RESTART IDENTITY; |
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
mysql: SHOW TABLES | |
postgresql: \d | |
postgresql: SELECT table_name FROM information_schema.tables WHERE table_schema = 'public'; | |
mysql: SHOW DATABASES | |
postgresql: \l | |
postgresql: SELECT datname FROM pg_database; | |
mysql: SHOW COLUMNS | |
postgresql: \d table | |
postgresql: SELECT column_name FROM information_schema.columns WHERE table_name ='table'; | |
mysql: DESCRIBE TABLE | |
postgresql: \d+ table | |
postgresql: SELECT column_name FROM information_schema.columns WHERE table_name ='table'; |
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
# | |
# https://www.digitalocean.com/community/tutorials/how-to-customize-the-postgresql-prompt-with-psqlrc-on-ubuntu-14-04 | |
# | |
\set PROMPT1 '%M:%> %n@%/%R%#%x ' | |
\set COMP_KEYWORD_CASE upper |
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 new user. | |
-- Create new database. | |
-- Assign the user to the database. | |
-- | |
CREATE USER username WITH PASSWORD 'password'; | |
CREATE DATABASE newdb TEMPLATE template0 ENCODING 'UNICODE'; | |
ALTER DATABASE newdb OWNER TO username; | |
GRANT ALL PRIVILEGES ON DATABASE newdb TO username; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment