$ /usr/bin/ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"
$ brew install postgresql
$ brew services start postgresql
$ brew services stop postgresql
$ psql postgres
\q
\list
or shortcut \l
in interactive session.\l
postgres
, template0
and template1
will already be present.testdb
database for example, we can give our own custom name.CREATE DATABASE testdb;
and it will create testdb
database, we can check by listing it using \l
command.
Alternatively, if we can Drop database using
DROP DATABASE testdb;
testuser
with password password
, we can create our own custom user with own password.CREATE USER testuser WITH PASSWORD 'password';
ALTER ROLE testuser SET client_encoding TO 'utf8';
ALTER ROLE testuser SET default_transaction_isolation TO 'read committed';
ALTER ROLE testuser SET timezone TO 'Asia/Kolkata';
GRANT ALL PRIVILEGES ON DATABASE testdb TO testuser;
testdb
created with all the privileges to testuser
.\l
.postgres
database.\connect
or shortcut \c
command\c testdb
\dt
command.\dt
person
table with id
, name
, email
and id set as PRIMARY KEY.CREATE TABLE person (id INTEGER PRIMARY KEY, name VARCHAR, email VARCHAR);
Alternatively, if you want you can drop table using
DROP TABLE person;
SELECT * FROM person;
person
table usingINSERT INTO person(id, name, email) VALUES(1, 'astik anand', 'astikanand@gmail.com');
pg_dump dbname > outputfile
command.$ pg_dump testdb > backup
pg_dump
.psql dbname < backupfile
.$ psql newtestdb < backup