PostgreSQL DDL Operations: Difference between revisions
Jump to navigation
Jump to search
No edit summary |
|||
Line 5: | Line 5: | ||
=Connect= | =Connect= | ||
{{Internal| | {{Internal|PostgreSQL_Concepts#Database|Database}} | ||
==Connect to the Default Database== | ==Connect to the Default Database== | ||
Line 53: | Line 53: | ||
=Users= | =Users= | ||
{{Internal| | {{Internal|PostgreSQL_Concepts#Database_User|Postgres Users}} | ||
==List Users== | ==List Users== |
Revision as of 06:41, 19 October 2018
Internal
Connect
Connect to the Default Database
psql -h localhost -U admin
Connect as a Specific User to a Database
psql -U <username> <dbname>
Database Cluster
initdb
initdb will create a new database cluster.
Database
List Databases
psql -l
or
SELECT datname FROM pg_database;
Create a Database
createdb <dbname>
createdb -h localhost -U admin playground
or
CREATE DATABASE <dbname>;
Connect to a Database
psql <database-name>
Drop a Database
DROP DATABASE
Users
List Users
psql \du
or
SELECT usename FROM pg_user;
Create User
createuser name
or
CREATE USER name;
Change Password
In psql, for the current user:
\password
or
ALTER USER user_name WITH PASSWORD 'new_password';
Tablespace
List Tablespaces
psql \db
Tables
List Tables
psql \dt
Create a Table
CREATE TABLE poc_library_component ( "id" integer NOT NULL, "name" text, "desc" text, CONSTRAINT poc_library_component_pk PRIMARY KEY (id) ) WITH ( OIDS=FALSE ); ALTER TABLE poc_library_component OWNER TO is3_as;
Note: apparently, Postgres does not like uppercases in column names.