check if yum repo contains desird packages
-------------------------------------------
yum list all | grep -i postgres
[root@simba ~]# yum list all | grep -i postgres
postgresql.x86_64 8.4.13-1.el6_3 @anaconda-RedHatEnterpriseLinux-201301301459.x86_64/6.4
postgresql-contrib.x86_64 8.4.13-1.el6_3 @localyumserver
postgresql-devel.x86_64 8.4.13-1.el6_3 @anaconda-RedHatEnterpriseLinux-201301301459.x86_64/6.4
postgresql-docs.x86_64 8.4.13-1.el6_3 @anaconda-RedHatEnterpriseLinux-201301301459.x86_64/6.4
postgresql-jdbc.noarch 8.4.701-8.el6 @localyumserver
postgresql-libs.x86_64 8.4.13-1.el6_3 @anaconda-RedHatEnterpriseLinux-201301301459.x86_64/6.4
postgresql-odbc.x86_64 08.04.0200-1.el6 @anaconda-RedHatEnterpriseLinux-201301301459.x86_64/6.4
postgresql-plperl.x86_64 8.4.13-1.el6_3 @localyumserver
postgresql-plpython.x86_64 8.4.13-1.el6_3 @localyumserver
postgresql-pltcl.x86_64 8.4.13-1.el6_3 @localyumserver
postgresql-server.x86_64 8.4.13-1.el6_3 @anaconda-RedHatEnterpriseLinux-201301301459.x86_64/6.4
postgresql-test.x86_64 8.4.13-1.el6_3 @localyumserver
postgresql.i686 8.4.13-1.el6_3 localyumserver
postgresql-devel.i686 8.4.13-1.el6_3 localyumserver
postgresql-libs.i686 8.4.13-1.el6_3 localyumserver
qt-postgresql.i686 1:4.6.2-25.el6 localyumserver
qt-postgresql.x86_64 1:4.6.2-25.el6 localyumserver
qt3-PostgreSQL.i686 3.3.8b-30.el6 localyumserver
qt3-PostgreSQL.x86_64 3.3.8b-30.el6 localyumserver
----------------------------------------------------------------------------------------------------------------------------
install postgres packages
--------------------------------
yum install postgresql*
Loaded plugins: product-id, refresh-packagekit, security, subscription-manager
This system is not registered to Red Hat Subscription Management. You can use subscription-manager to register.
Setting up Install Process
or
yum install postgresql-server.x86_64
Path where Postgres is installed
-----------------------------------
/var/lib/pgsql/data
[root@simba pgsql]# ls
backups data
Confiuration path of postgresql
=================================
/usr/lib64/pgsql
/usr/share/pgsql/contrib
The data cluster is created by default in /var/lib/pgsql/9.3/data and the extensions folder is in /usr/pgsql-9.3/share/extension/ and the binaries are in /usr/pgsql-9.3/bin.
-----------------------------------
Initialize
-----------------------------------
The first command (only needed once) is to initialize the database in PGDATA.
service <name> initdb
E.g. for version 9.4:
============================
service postgresql-9.4 initdb
OR in our case
=============================
[root@simba usr]# service postgresql initdb
Initializing database: [ OK ]
You have new mail in /var/spool/mail/root
Starting service
If the previous command did not work, try directly calling the setup binary, located in a similar naming scheme:
/usr/pgsql-y.x/bin/postgresqlyx-setup initdb
E.g. for version 9.4:
===========================================
/usr/pgsql-9.4/bin/postgresql94-setup initdb
RHEL 7.1+ and CentOS 7.1+ are a bit different. Use:
===================================================
postgresql-setup initdb
Startup
-----------------------------------------------------------------
If you want PostgreSQL to start automatically when the OS starts:
chkconfig <name> on
[root@simba usr]#chkconfig postgresql on
E.g. for version 9.4:
============================
chkconfig postgresql-9.4 on
In RHEL 7+, try:
systemctl enable postgresql
===========================
Control service
-----------------------------------------------------------------
To control the database service, use:
service <name> <command>
where <command> can be:
start : start the database
stop : stop the database
restart : stop/start the database; used to read changes to core configuration files
reload : reload pg_hba.conf file while keeping database running
E.g. to start version 9.4:
===========================
service postgresql-9.4 start
OR in our case
============================
[root@simba usr]# service postgresql start
Starting postgresql service: [ OK ]
[root@simba usr]#
or
[root@simba usr]# /etc/init.d/postgresql start
With RHEL 7.1+ and CentOS 7.1+, Systemd is introduced. Use this instead:
========================================================================
systemctl enable postgresql
systemctl start postgresql
Removing
------------------------------------------------------------------------
To remove everything:
yum erase postgresql94*
Or remove individual packages as desired.
-----------------------------------------
Verify PostgreSQL Installation
------------------------------------------------------------------------
After completing above steps, you have installed PostgreSQL 9.4 on your server, Let’s login to postfix to verify that installation completed successfully.
Log Into the Postgres Database
==============================
By default, postgres creates a user and a database called postgres.
The default security scheme assumes that the postgres user will only be accessible to those who need access. This can be controlled by setting up sudo rules.
We interact with the postgres database software through an interface called psql. It provides a prompt where we can manipulate and query for data.
log into the postgres user
Your prompt will change. You can now connect to the database that matches your username by typing:
-------------------------------------
[root@simba usr]# su - postgres
-bash-4.1$ psql
psql (8.4.13)
Type "help" for help.
You may create password for user postgres for security purpose.
================================================================
postgres=# \password postgres
List of roles
==============================================================================
postgres=# \du
Role name | Attributes | Member of
-----------+-------------+-----------
postgres | Superuser | {}
: Create role
: Create DB
List of databases
================================================================================
postgres=# \l
Name | Owner | Encoding | Collation | Ctype | Access privileg
es
-----------+----------+----------+-------------+-------------+------------------
-----
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/post
gres
template1 | postgres | UTF8 | en_US.UTF-8 | en_US.UTF-8 | =c/postgres
: postgres=CTc/post
gres
(3 rows)
If you need to exit this interface, you can type this at any time:
postgres=# \q
Afterwards, to get back to the root user shell, you can type:
exit
Some Helpful psql Commands
=================================================================================
Here are a few commands that can help you get an idea of your current environment:
\?: Get a full list of psql commands, including those not listed here.
\h: Get help on SQL commands. You can follow this with a specific command to get help with the syntax.
\q: Quit the psql program and exit to the Linux prompt.
\d: List available tables, views, and sequences in current database.
\du: List available roles
\dp: List access privileges
\dt: List tables
\l: List databases
\c: Connect to a different database. Follow this by the database name.
\password: Change the password for the username that follows.
\conninfo: Get information about the current database and connection.
-------------------------------------------
yum list all | grep -i postgres
[root@simba ~]# yum list all | grep -i postgres
postgresql.x86_64 8.4.13-1.el6_3 @anaconda-RedHatEnterpriseLinux-201301301459.x86_64/6.4
postgresql-contrib.x86_64 8.4.13-1.el6_3 @localyumserver
postgresql-devel.x86_64 8.4.13-1.el6_3 @anaconda-RedHatEnterpriseLinux-201301301459.x86_64/6.4
postgresql-docs.x86_64 8.4.13-1.el6_3 @anaconda-RedHatEnterpriseLinux-201301301459.x86_64/6.4
postgresql-jdbc.noarch 8.4.701-8.el6 @localyumserver
postgresql-libs.x86_64 8.4.13-1.el6_3 @anaconda-RedHatEnterpriseLinux-201301301459.x86_64/6.4
postgresql-odbc.x86_64 08.04.0200-1.el6 @anaconda-RedHatEnterpriseLinux-201301301459.x86_64/6.4
postgresql-plperl.x86_64 8.4.13-1.el6_3 @localyumserver
postgresql-plpython.x86_64 8.4.13-1.el6_3 @localyumserver
postgresql-pltcl.x86_64 8.4.13-1.el6_3 @localyumserver
postgresql-server.x86_64 8.4.13-1.el6_3 @anaconda-RedHatEnterpriseLinux-201301301459.x86_64/6.4
postgresql-test.x86_64 8.4.13-1.el6_3 @localyumserver
postgresql.i686 8.4.13-1.el6_3 localyumserver
postgresql-devel.i686 8.4.13-1.el6_3 localyumserver
postgresql-libs.i686 8.4.13-1.el6_3 localyumserver
qt-postgresql.i686 1:4.6.2-25.el6 localyumserver
qt-postgresql.x86_64 1:4.6.2-25.el6 localyumserver
qt3-PostgreSQL.i686 3.3.8b-30.el6 localyumserver
qt3-PostgreSQL.x86_64 3.3.8b-30.el6 localyumserver
----------------------------------------------------------------------------------------------------------------------------
install postgres packages
--------------------------------
yum install postgresql*
Loaded plugins: product-id, refresh-packagekit, security, subscription-manager
This system is not registered to Red Hat Subscription Management. You can use subscription-manager to register.
Setting up Install Process
or
yum install postgresql-server.x86_64
Path where Postgres is installed
-----------------------------------
/var/lib/pgsql/data
[root@simba pgsql]# ls
backups data
Confiuration path of postgresql
=================================
/usr/lib64/pgsql
/usr/share/pgsql/contrib
The data cluster is created by default in /var/lib/pgsql/9.3/data and the extensions folder is in /usr/pgsql-9.3/share/extension/ and the binaries are in /usr/pgsql-9.3/bin.
-----------------------------------
Initialize
-----------------------------------
The first command (only needed once) is to initialize the database in PGDATA.
service <name> initdb
E.g. for version 9.4:
============================
service postgresql-9.4 initdb
OR in our case
=============================
[root@simba usr]# service postgresql initdb
Initializing database: [ OK ]
You have new mail in /var/spool/mail/root
Starting service
If the previous command did not work, try directly calling the setup binary, located in a similar naming scheme:
/usr/pgsql-y.x/bin/postgresqlyx-setup initdb
E.g. for version 9.4:
===========================================
/usr/pgsql-9.4/bin/postgresql94-setup initdb
RHEL 7.1+ and CentOS 7.1+ are a bit different. Use:
===================================================
postgresql-setup initdb
Startup
-----------------------------------------------------------------
If you want PostgreSQL to start automatically when the OS starts:
chkconfig <name> on
[root@simba usr]#chkconfig postgresql on
E.g. for version 9.4:
============================
chkconfig postgresql-9.4 on
In RHEL 7+, try:
systemctl enable postgresql
===========================
Control service
-----------------------------------------------------------------
To control the database service, use:
service <name> <command>
where <command> can be:
start : start the database
stop : stop the database
restart : stop/start the database; used to read changes to core configuration files
reload : reload pg_hba.conf file while keeping database running
E.g. to start version 9.4:
===========================
service postgresql-9.4 start
OR in our case
============================
[root@simba usr]# service postgresql start
Starting postgresql service: [ OK ]
[root@simba usr]#
or
[root@simba usr]# /etc/init.d/postgresql start
With RHEL 7.1+ and CentOS 7.1+, Systemd is introduced. Use this instead:
========================================================================
systemctl enable postgresql
systemctl start postgresql
Removing
------------------------------------------------------------------------
To remove everything:
yum erase postgresql94*
Or remove individual packages as desired.
-----------------------------------------
Verify PostgreSQL Installation
------------------------------------------------------------------------
After completing above steps, you have installed PostgreSQL 9.4 on your server, Let’s login to postfix to verify that installation completed successfully.
Log Into the Postgres Database
==============================
By default, postgres creates a user and a database called postgres.
The default security scheme assumes that the postgres user will only be accessible to those who need access. This can be controlled by setting up sudo rules.
We interact with the postgres database software through an interface called psql. It provides a prompt where we can manipulate and query for data.
log into the postgres user
Your prompt will change. You can now connect to the database that matches your username by typing:
-------------------------------------
[root@simba usr]# su - postgres
-bash-4.1$ psql
psql (8.4.13)
Type "help" for help.
You may create password for user postgres for security purpose.
================================================================
postgres=# \password postgres
List of roles
==============================================================================
postgres=# \du
Role name | Attributes | Member of
-----------+-------------+-----------
postgres | Superuser | {}
: Create role
: Create DB
List of databases
================================================================================
postgres=# \l
Name | Owner | Encoding | Collation | Ctype | Access privileg
es
-----------+----------+----------+-------------+-------------+------------------
-----
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/post
gres
template1 | postgres | UTF8 | en_US.UTF-8 | en_US.UTF-8 | =c/postgres
: postgres=CTc/post
gres
(3 rows)
If you need to exit this interface, you can type this at any time:
postgres=# \q
Afterwards, to get back to the root user shell, you can type:
exit
Some Helpful psql Commands
=================================================================================
Here are a few commands that can help you get an idea of your current environment:
\?: Get a full list of psql commands, including those not listed here.
\h: Get help on SQL commands. You can follow this with a specific command to get help with the syntax.
\q: Quit the psql program and exit to the Linux prompt.
\d: List available tables, views, and sequences in current database.
\du: List available roles
\dp: List access privileges
\dt: List tables
\l: List databases
\c: Connect to a different database. Follow this by the database name.
\password: Change the password for the username that follows.
\conninfo: Get information about the current database and connection.
Comments
Post a Comment