Tuesday 6 December 2016

How to schedule postgresql auto vacuum in linux



Step 1: Create a .pgpass file under your home directory.


                   [root@centos6 ~]# vim .pgpass

                                localhost:5432:DB-Name:Username:Password


Step 2: Install Crond packages.  http://www.admincool.in/2016/09/how-to-scheduling-crontab-for-     backup.html

Step 3: Edit crontab


                  [root@centos6 ~]# crontab -e

                  30      10      *      *      *      /opt/PostgreSQL/9.4/bin/psql dbname=bayaTRADETest --username=dbuser -c 'VACUUM FULL VERBOSE'


Step 4: Restart crontab


                 # service crond restart


Step 5: Add crontab on startup


                # chkconfig crond on





Description


Vacuum reclaims storage occupied by dead tuples. In normal PostgreSQL operation, tuples that are deleted or obsoleted by an update are not physically removed from their table; they remain present until a Vacuum is done. Therefore it's necessary to do Vacuum periodically, especially on frequently-updated tables.


With no parameter, Vacuum processes every table in the current database that the current user has permission to vacuum. With a parameter, Vacuum processes only that table.

Plain Vacuum (without FULL) simply reclaims space and makes it available for re-use. This form of the command can operate in parallel with normal reading and writing of the table, as an exclusive lock is not obtained. However, extra space is not returned to the operating system (in most cases); it's just kept available for re-use within the same table. Vacuum FULL rewrites the entire contents of the table into a new disk file with no extra space, allowing unused space to be returned to the operating system. This form is much slower and requires an exclusive lock on each table while it is being processed.

Parameters 


FULL

Selects "full" vacuum, which can reclaim more space, but takes much longer and exclusively locks the table. This method also requires extra disk space, since it writes a new copy of the table and doesn't release the old copy until the operation is complete. Usually this should only be used when a significant amount of space needs to be reclaimed from within the table.

FREEZE

Selects aggressive "freezing" of tuples. Specifying FREEZE is equivalent to performing Vacuum with the vacuum_freeze_min_age parameter set to zero.

VERBOSE

Prints a detailed vacuum activity report for each table.

ANALYZE

Updates statistics used by the planner to determine the most efficient way to execute a query.

table

The name (optionally schema-qualified) of a specific table to vacuum. Defaults to all tables in the current database.

column

The name of a specific column to analyze. Defaults to all columns. If a column list is specified, ANALYZE is implied.


PostgreSQL Vacuum graphically 

Step 1: Right click on database and select maintenance. It will open a pop up window.

Step 2: Select maintenance operation as VACUUM.

Step 3: Select VACUUM option as FULL

Step 4: Click OK










How to schedule postgresql auto backup in linux


Step 1: Create a .pgpass file under your home directory.

                   [root@centos6 ~]# vim .pgpass

                                localhost:5432:DB-Name:Username:Password


Step 2: Install Crond packages.  http://www.admincool.in/2016/09/how-to-scheduling-crontab-for-     backup.html


Step3: Edit crontab


                  [root@centos6 ~]# crontab -e

                  30      10      *      *      *      /opt/PostgreSQL/9.4/bin/pg_dump -U username --format=c --file=/postgres-backup/dbname.backup dbname


The backup of database will scheduled every day at 10.30 AM under 'postgres-backup' directory.


Step 4: Restart crontab


                 # service crond restart


Step 5: Add crontab on startup


                # chkconfig crond on



Synopsis

pg_dump [connection-option...] [option...] [dbname]

Description


pg_dump is a utility for backing up a PostgreSQL database. It makes consistent backups even if the database is being used concurrently. pg_dump does not block other users accessing the database (readers or writers).

Dumps can be output in script or archive file formats. Script dumps are plain-text files containing the SQL commands required to reconstruct the database to the state it was in at the time it was saved. To restore from such a script, feed it to psql. Script files can be used to reconstruct the database even on other machines and other architectures; with some modifications, even on other SQL database products.

The alternative archive file formats must be used with pg_restore to rebuild the database. They allow pg_restore to be selective about what is restored, or even to reorder the items prior to being restored. The archive file formats are designed to be portable across architectures.

When used with one of the archive file formats and combined with pg_restore, pg_dump provides a flexible archival and transfer mechanism. pg_dump can be used to backup an entire database, then pg_restore can be used to examine the archive and/or select which parts of the database are to be restored. The most flexible output file format is the "custom" format (-Fc). It allows for selection and reordering of all archived items, and is compressed by default.


Options

-U username
--username=username
User name to connect as.

-F format
--format=format
Selects the format of the output. format can be one of the following:

p
plain
Output a plain-text SQL script file (the default).

c
custom
Output a custom-format archive suitable for input into pg_restore. Together with the directory output format, this is the most flexible output format in that it allows manual selection and reordering of archived items during restore. This format is also compressed by default.

d
directory
Output a directory-format archive suitable for input into pg_restore. This will create a directory with one file for each table and blob being dumped, plus a so-called Table of Contents file describing the dumped objects in a machine-readable format that pg_restore can read. A directory format archive can be manipulated with standard Unix tools; for example, files in an uncompressed archive can be compressed with the gzip tool. This format is compressed by default.

t
tar
Output a tar-format archive suitable for input into pg_restore. The tar format is compatible with the directory format: extracting a tar-format archive produces a valid directory-format archive. However, the tar format does not support compression. Also, when using tar format the relative order of table data items cannot be changed during restore.

-i
--ignore-version
A deprecated option that is now ignored.









How to configure ftp server on centos


FTP is a file transferring protocol used to transfer form one host to another over TCP.
Package used for ftp server is vsftpd (Very Secure FTP Daemon). It is able to handle number of connections efficiently and securely. It uses port 21.

FTP server is used in wide area network. No mounting is needed. File uplod and download can be possible. FTP server offers two types of login, which are anonymous login and local user login.


Configuration


Step 1: Install vsftpd package

       [root@centos6 ~]# yum install vsftpd




Step 2: After install vsftpd package open configuration file and edit the file as following.


       [root@centos6 ~]# vim /etc/vsftpd/vsftpd.conf 

anonymous_enable=NO

local_enable=YES

write_enable=YES

chroot_local_user=YES

      Note: If 'anonymous_enable=YES', anyone can access ftp server without username and password.


Step 3: Create a folder where to store ftp data. In my case I am going to install folder under '/' directory.

       [root@centos6 /]# mkdir FTP-Share


Step 4: Create a ftp user with home directory as above created folder

       [root@centos6 /]# useradd -d /FTP-Share/alleria alleria
       [root@centos6 /]# passwd alleria





Step 5: Start the vsftpd service and add on startup

       [root@centos6 /]# service vsftpd start
       [root@centos6 /]# chkconfig vsftpd on

Step 6: Now test ftp. I created a file under user alleria's home directory.

       [root@centos6 /]# cd FTP-Share/alleria/
       [root@centos6 alleria]# touch alleria.txt