Login psql:
-bash-4.1$ psql -U postgres
Password for user postgres:
psql (8.4.13, server 10.10)
WARNING: psql version 8.4, server version 10.10.
Some psql features might not work.
Type "help" for help.
List of database:
postgres=# \l
List of databases
Name | Owner | Encoding | Collation | Ctype | Access privileges
-----------+----------+----------+-------------+-------------+-----------------------
magicball | postgres | UTF8 | en_US.UTF-8 | en_US.UTF-8 | =Tc/postgres
: postgres=CTc/postgres
: magic=CTc/postgres
postgres | postgres | UTF8 | en_US.UTF-8 | en_US.UTF-8 |
template0 | postgres | UTF8 | en_US.UTF-8 | en_US.UTF-8 | =c/postgres
: postgres=CTc/postgres
template1 | postgres | UTF8 | en_US.UTF-8 | en_US.UTF-8 | =c/postgres
: postgres=CTc/postgres
(4 rows)
Create a user :
postgres=# CREATE USER hr WITH ENCRYPTED PASSWORD 'welcome1';
CREATE ROLE
Create a database:
postgres=# CREATE DATABASE hrdb
postgres-# WITH ENCODING='UTF8'
postgres-# OWNER=hr
postgres-# CONNECTION LIMIT=25;
CREATE DATABASE
postgres=# \l
List of databases
Name | Owner | Encoding | Collation | Ctype | Access privileges
-----------+----------+----------+-------------+-------------+-----------------------
hrdb | hr | UTF8 | en_US.UTF-8 | en_US.UTF-8 |
magicball | postgres | UTF8 | en_US.UTF-8 | en_US.UTF-8 | =Tc/postgres
: postgres=CTc/postgres
: magic=CTc/postgres
postgres | postgres | UTF8 | en_US.UTF-8 | en_US.UTF-8 |
template0 | postgres | UTF8 | en_US.UTF-8 | en_US.UTF-8 | =c/postgres
: postgres=CTc/postgres
template1 | postgres | UTF8 | en_US.UTF-8 | en_US.UTF-8 | =c/postgres
: postgres=CTc/postgres
(5 rows)
-bash-4.1$ psql -l
Password:
List of databases
Name | Owner | Encoding | Collation | Ctype | Access privileges
-----------+----------+----------+-------------+-------------+-----------------------
hrdb | hr | UTF8 | en_US.UTF-8 | en_US.UTF-8 |
magicball | postgres | UTF8 | en_US.UTF-8 | en_US.UTF-8 | =Tc/postgres
: postgres=CTc/postgres
: magic=CTc/postgres
postgres | postgres | UTF8 | en_US.UTF-8 | en_US.UTF-8 |
template0 | postgres | UTF8 | en_US.UTF-8 | en_US.UTF-8 | =c/postgres
: postgres=CTc/postgres
template1 | postgres | UTF8 | en_US.UTF-8 | en_US.UTF-8 | =c/postgres
: postgres=CTc/postgres
test | postgres | UTF8 | en_US.UTF-8 | en_US.UTF-8 |
(6 rows)
Connect to database:
-bash-4.1$ psql -d hrdb -U hr -W
Password for user hr:
psql (8.4.13, server 10.10)
WARNING: psql version 8.4, server version 10.10.
Some psql features might not work.
Type "help" for help.
Check all the tables in database:
hrdb=> \dt
No relations found.
Create a table:
hrdb=> CREATE TABLE role(
hrdb(> role_id serial PRIMARY KEY,
hrdb(> role_name VARCHAR (255) UNIQUE NOT NULL
hrdb(> );
CREATE TABLE
hrdb=> \dt
List of relations
Schema | Name | Type | Owner
--------+---------+-------+-------
public | role | table | hr
(1 row)
Insert data into tables:
hrdb=> insert into role(role_id,role_name)
hrdb-> values
hrdb-> (3,'Manager');
INSERT 0 1
Find the details of tables:
hrdb=> select * from role;
role_id | role_name
---------+-----------
1 | worker
2 | team lead
3 | Manager
(3 rows)
Exit from database:
hrdb=> \q
-bash-4.1$
Thanks,
-bash-4.1$ psql -U postgres
Password for user postgres:
psql (8.4.13, server 10.10)
WARNING: psql version 8.4, server version 10.10.
Some psql features might not work.
Type "help" for help.
List of database:
postgres=# \l
List of databases
Name | Owner | Encoding | Collation | Ctype | Access privileges
-----------+----------+----------+-------------+-------------+-----------------------
magicball | postgres | UTF8 | en_US.UTF-8 | en_US.UTF-8 | =Tc/postgres
: postgres=CTc/postgres
: magic=CTc/postgres
postgres | postgres | UTF8 | en_US.UTF-8 | en_US.UTF-8 |
template0 | postgres | UTF8 | en_US.UTF-8 | en_US.UTF-8 | =c/postgres
: postgres=CTc/postgres
template1 | postgres | UTF8 | en_US.UTF-8 | en_US.UTF-8 | =c/postgres
: postgres=CTc/postgres
(4 rows)
Create a user :
postgres=# CREATE USER hr WITH ENCRYPTED PASSWORD 'welcome1';
CREATE ROLE
Create a database:
postgres=# CREATE DATABASE hrdb
postgres-# WITH ENCODING='UTF8'
postgres-# OWNER=hr
postgres-# CONNECTION LIMIT=25;
CREATE DATABASE
postgres=# \l
List of databases
Name | Owner | Encoding | Collation | Ctype | Access privileges
-----------+----------+----------+-------------+-------------+-----------------------
hrdb | hr | UTF8 | en_US.UTF-8 | en_US.UTF-8 |
magicball | postgres | UTF8 | en_US.UTF-8 | en_US.UTF-8 | =Tc/postgres
: postgres=CTc/postgres
: magic=CTc/postgres
postgres | postgres | UTF8 | en_US.UTF-8 | en_US.UTF-8 |
template0 | postgres | UTF8 | en_US.UTF-8 | en_US.UTF-8 | =c/postgres
: postgres=CTc/postgres
template1 | postgres | UTF8 | en_US.UTF-8 | en_US.UTF-8 | =c/postgres
: postgres=CTc/postgres
(5 rows)
-bash-4.1$ psql -l
Password:
List of databases
Name | Owner | Encoding | Collation | Ctype | Access privileges
-----------+----------+----------+-------------+-------------+-----------------------
hrdb | hr | UTF8 | en_US.UTF-8 | en_US.UTF-8 |
magicball | postgres | UTF8 | en_US.UTF-8 | en_US.UTF-8 | =Tc/postgres
: postgres=CTc/postgres
: magic=CTc/postgres
postgres | postgres | UTF8 | en_US.UTF-8 | en_US.UTF-8 |
template0 | postgres | UTF8 | en_US.UTF-8 | en_US.UTF-8 | =c/postgres
: postgres=CTc/postgres
template1 | postgres | UTF8 | en_US.UTF-8 | en_US.UTF-8 | =c/postgres
: postgres=CTc/postgres
test | postgres | UTF8 | en_US.UTF-8 | en_US.UTF-8 |
(6 rows)
Connect to database:
-bash-4.1$ psql -d hrdb -U hr -W
Password for user hr:
psql (8.4.13, server 10.10)
WARNING: psql version 8.4, server version 10.10.
Some psql features might not work.
Type "help" for help.
Check all the tables in database:
hrdb=> \dt
No relations found.
Create a table:
hrdb=> CREATE TABLE role(
hrdb(> role_id serial PRIMARY KEY,
hrdb(> role_name VARCHAR (255) UNIQUE NOT NULL
hrdb(> );
CREATE TABLE
hrdb=> \dt
List of relations
Schema | Name | Type | Owner
--------+---------+-------+-------
public | role | table | hr
(1 row)
Insert data into tables:
hrdb=> insert into role(role_id,role_name)
hrdb-> values
hrdb-> (3,'Manager');
INSERT 0 1
Find the details of tables:
hrdb=> select * from role;
role_id | role_name
---------+-----------
1 | worker
2 | team lead
3 | Manager
(3 rows)
Exit from database:
hrdb=> \q
-bash-4.1$
Thanks,
No comments:
Post a Comment