Skip to content

Instantly share code, notes, and snippets.

@TopekoX
Created October 18, 2017 06:29
Show Gist options
  • Save TopekoX/38000e2a59022701b8371b187d8db417 to your computer and use it in GitHub Desktop.
Save TopekoX/38000e2a59022701b8371b187d8db417 to your computer and use it in GitHub Desktop.
# login root
su
systemctl start postgresql
su - postgres
psql
# edit password postgres
\password postgres
# create user & database
CREATE USER ucup WITH PASSWORD 'xxxxxx';
CREATE DATABASE office OWNER ucup;
# with shell
$ createuser ucup
$ createdb --owner=ucup office
# show databases
\l
# select database
\c office
# via command prompt
psql -h localhost -p 5432 -U ucup office
# drop database
DROP DATABASE office
# via command prompt
dropdb -h localhost -p 5432 -U ucup office
# create table
CREATE TABLE table_name(
column1 datatype,
column2 datatype,
column3 datatype,
.....
columnN datatype,
PRIMARY KEY( one or more columns )
);
# show tables
\d
\d table_name
# drop table
DROP TABLE table_name
drop table department, company
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment