Skip to main content

Postgres Error and troubleshooting

===============================================================================
What if we directly want to access the db without logining into postgres user
-----------------------------------------------------------------------------

Step 1 login as root and give password for postgres user if not given
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
login as: root
root@10.249.95.96's password:
Last login: Fri Sep 11 21:19:05 2015 from 10.33.177.202
[root@localhost ~]# sudo -u postgres psql
could not change directory to "/root"
psql (8.4.9)
Type "help" for help.

postgres=# \password
Enter new password:    ##here password is postgres
Enter it again:

Step 2 quit DB
+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
postgres=# \q

Step 3 Try to login to PSQL db from root user or any other user
+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
------------------------------------------------------------------------
[root@localhost ~]# psql -U postgres

psql: FATAL:  Ident authentication failed for user "postgres"
You have new mail in /var/spool/mail/root
[root@localhost ~]# psql -U postgres -h localhost
psql: FATAL:  Ident authentication failed for user "postgres"
[root@localhost ~]# cd /var/lib/pgsql/
You have mail in /var/spool/mail/root
------------------------------------------------------------------------
You are getting FATAL:  Ident authentication failed for user "postgres" Error

We need to Allow local user connections to access pgssl, for this edit pg_hba.conf
===============================================================

The file pg_hba.conf governs the basic constraints underlying connection to PostgreSQL. By default, these settings are very conservative. Specifically, local connections are not allowed for the postgres user.

To allow this:

As a super user, open /var/lib/pgsql/data/pg_hba.conf file
---------------------------------------------------------------
[root@localhost pgsql]# ls
backups  data  pgstartup.log
[root@localhost pgsql]# cd data/
[root@localhost data]# ls
base         pg_ident.conf  pg_subtrans  pg_xlog
global       pg_log         pg_tblspc    postgresql.conf
pg_clog      pg_multixact   pg_twophase  postmaster.opts
pg_hba.conf  pg_stat_tmp    PG_VERSION   postmaster.pid
[root@localhost data]# vim pg_hba.conf

Scroll down to the line that describes local network. It may look like this:
------------------------------------------------------------------------------

# TYPE  DATABASE    USER        CIDR-ADDRESS          METHOD

# "local" is for Unix domain socket connections only
local   all         all                               ident
# IPv4 local connections:
host    all         all         127.0.0.1/32          ident
# IPv6 local connections:
host    all         all         ::1/128               ident


Change the ident method to trust or md5.
------------------------------------------------------------------------------

Using trust allows the all local users to connect to the database without a password. This is convenience, but insecure. If you want a little more security, replace trust with md5, and use the password you set in the previous section to connect.

# TYPE  DATABASE    USER        CIDR-ADDRESS          METHOD

# "local" is for Unix domain socket connections only
local   all         all                               md5 #ident
# IPv4 local connections:
host    all         all         127.0.0.1/32          md5 #ident
# IPv6 local connections:
host    all         all         ::1/128               md5 #ident



Save and close the file.
-----------------------------
Restart PostgreSQL:
-----------------------------
[root@localhost data]# sudo /etc/init.d/postgresql restart
Stopping postgresql service:                               [  OK  ]
Starting postgresql service:                               [  OK  ]


To test your connection using psql, run the following command:psql -U postgres -W and enter your password when prompted. You should be able to access the psql console.
--------------------------------------------------------------------------------------------------------------------------------------
[root@localhost data]# psql -U postgres -W
Password for user postgres:
psql (8.4.9)
Type "help" for help.

postgres=# \q
You have mail in /var/spool/mail/root

[root@localhost data]# psql -U postgres
Password for user postgres:
psql (8.4.9)
Type "help" for help.

postgres=# \q

Comments

  1. Further Links: http://www.unixmen.com/postgresql-9-4-released-install-centos-7/
    http://tecadmin.net/install-postgresql-on-centos-rhel-and-fedora/#
    http://yum.postgresql.org/repopackages.php

    ReplyDelete

Post a Comment

Popular posts from this blog

20 perl programming tips

1. List all Installed Perl Modules from Unix Command Line Get a list of all installed perl modules as shown below. $ perl -MFile::Find=find -MFile::Spec::Functions -Tlw -e 'find { wanted => sub { print canonpath $_ if /\.pm\z/ }, no_chdir => 1 }, @INC' /usr/lib/perl5/vendor_perl/5.8.8/i386-linux-thread-multi/HTML/Filter.pm /usr/lib/perl5/vendor_perl/5.8.8/i386-linux-thread-multi/HTML/LinkExtor.pm /usr/lib/perl5/vendor_perl/5.8.8/i386-linux-thread-multi/HTML/PullParser.pm /usr/lib/perl5/vendor_perl/5.8.8/i386-linux-thread-multi/HTML/Parser.pm /usr/lib/perl5/vendor_perl/5.8.8/i386-linux-thread-multi/HTML/TokeParser.pm ..... In the above example, File::Find  and  File::Spec::Functions  module are used to list all installed modules. -M option  loads the module. It executes  use module  before executing the script -T option  enables taint checking, which instructs perl to keep track of data from the user and avoid doing anything insecure w...

Perl and Excel: How to Read, Write, Parse Excel Files using Perl

If you want to manipulate excel files programmatically, you can use Perl Spreadsheet module, which provides an object interface that makes it easier to create and parse Excel files. Install Spreadsheet WriteExcel Module Method 1: Standard install using make Download the zipped tar file of  Spreadsheet-ParseExcel  and  Spreadsheet-WriteExcel  from cpan. Untar and unzip the module as follows: tar -zxvf Spreadsheet-WriteExcel.tar.gz cd to the directory the tar creates. Execute the steps below to to install the Spreadsheet-WriteExcel module. perl Makefile.PL make make test make install Use the above procedure to install Spreadsheet-ParseExcel also. Method 2: CPAN.pm install If you have CPAN.pm configured you can install the module as follows: perl -MCPAN -e 'install "Spreadsheet::WriteExcel"' perl -MCPAN -e 'install "Spreadsheet::ParseExcel"' For additional installation help refer to: How To Install Perl Modules Manually and Using ...

How to Connect to MySQL from Perl

How do I connect to a MySQL database from a perl program? use perl DBI module to connect to a MySQL database as explained below. If you don’t have perl DBI and DBD::mysql module installed, install perl module using cpan as we discussed earlier. # perl -MCPAN -e shell cpan> install DBI cpan> install DBD::mysql On a very high level, you’ll have to do the following three steps to connect to a MySQL database and get data. 1. Connect to the MySQL Database In the DBI module, you’ll use the connect function as shown below. $dbc = DBI->connect($source, $username, $password) DBI->connect function takes the following three arguments: $source – This is in the format of “DBI:mysql:[database]:[hostname]”. Replace the [database] and [hostname] with values from your system. In the example shown below, it is connecting to the database called “mycompany” that is running on the localhost. $username – The username that is used to connect to the MySQL database. $pass...