Troubleshooting basic PostgreSQL Problems In Linux (RHEL)

Encountered 2 PostgreSQL problems today. One was about the wrong permission to opt/PostgreSQL/9.3/data directory.

[root@server pg_log]# /etc/rc.d/init.d/postgresql-9.3 restart
Restarting PostgreSQL 9.3:
waiting for server to shut down.... done
server stopped
waiting for server to start........ stopped waiting
pg_ctl: could not start server
Examine the log output.
PostgreSQL 9.3 did not start in a timely fashion, please see /opt/PostgreSQL/9.3/data/pg_log/startup.log for details

Examining the log file pointed to below.

FATAL:  data directory "/opt/PostgreSQL/9.3/data" has group or world access

DETAIL:  Permissions should be u=rwx (0700)

So, the trick was to chmod 0700 to opt/PostgreSQL/9.3/data directory 😉 And it solved it 🙂

[root@server pg_log]# /etc/rc.d/init.d/postgresql-9.3 restart
Restarting PostgreSQL 9.3:
pg_ctl: PID file "/opt/PostgreSQL/9.3/data/" does not exist
Is server running?
starting server anyway
waiting for server to start.... done
server started
PostgreSQL 9.3 restarted successfully

Other problem was with a normal user trying to restart PostgreSQL server. So I made below changes to the /etc/sudoers file. 

shashank ALL=(ALL) NOPASSWD: /etc/rc.d/init.d/postgresql-9.3 restart
 shashank ALL=(ALL) NOPASSWD: /etc/rc.d/init.d/postgresql-9.3 start
 shashank ALL=(ALL) NOPASSWD: /etc/rc.d/init.d/postgresql-9.3 stop

prefixing sudo to /etc/rc.d/init.d/postgresql-9.3 restart did the trick 😉

Install node.js On RHEL/CentOS

Installing node.js is as simple as downloading the tarball from Node.js, unpacking the contents to any chosen directory & setting the PATH variable. Below are the steps to install it in 2 mins 😉 Here in this case, I copied the tarball to /opt/app directory.

  • [root@server ~]# cd /opt/app
  • [root@server node-v0.10.35-linux-x64]# tar zxf /opt/app/node-v0.10.35-linux-x64.tar.gz
  • [root@server node-v0.10.35-linux-x64]# echo “export PATH=$PATH:/opt/app/node-v0.10.35-linux-x64/bin” >> /etc/bashrc
  • [root@server node-v0.10.35-linux-x64]# source /etc/bashrc
  • Add below line in /etc/profile : –

export PATH=/opt/app/node-v0.10.35-linux-x64/bin:$PATH

  • [root@server node-v0.10.35-linux-x64]# source /etc/profile
  • Check if it’s installed or not : –
[root@vhedtdspci01 node-v0.10.35-linux-x64]# which node
[root@vhedtdspci01 node-v0.10.35-linux-x64]# node --version

Checking NIC Speed In Linux

At times I (we) need to check the NIC (Network Interface Card) speed on a Linux machine. Here is how to do it 🙂

[root@server ~]# ethtool eth0
Settings for eth0:
 Supported ports: [ ]
 Supported link modes:
 Supports auto-negotiation: No
 Advertised link modes: Not reported
 Advertised auto-negotiation: No
 Speed: 10000Mb/s
 Duplex: Full
 Port: Unknown! (255)
 Transceiver: internal
 Auto-negotiation: off
Link detected: yes

Installing git 1.9.0 on RHEL

Installing git was quite some pain today 😦 Was trying to find the RPM but couldn’t. Tried using the YUM, but no success once again 😦 So I went for the manual install of (g)it 😉

Below are the steps I followed.

  • Download git tarball & its  signature file from this link.
  • Place this tarball inside /usr/src.
  • Run tar xzf git-1.9.0.tar.gz
  • cd git-1.9.0
  • make prefix=/usr/bin/git
  • make prefix=/usr/bin/git install
  • echo “export PATH=$PATH:/usr/bin/git/bin” >> /etc/bashrc
  • source /etc/bashrc
  • Restart your session or open a new session.
  • Verify by issuing git –version

[root@server git-1.9.0]# git –version
git version 1.9.0
[root@server git-1.9.0]# which git

P.S. You may receive below errors while installing git. So, make sure you have installed these packages before trying to install git :- 


Errors :-

* new build flags cc credential-store.o in file included from credential-store.c:1: cache.h:19:18: warning: zlib.h: no such file or directory in file included from credential-store.c:1: cache.h:21: error: expected specifier-qualifier-list before ‘z_stream’ make: *** [credential-store.o] error 1

http.c:1578: error: ‘struct http_object_request’ has no member named ‘slot’

P.P.S. – If somehow, above steps fail. Try below steps : –

  • cd /usr/src/git-1.9.0
  • ./configure
  • make
  • make install
  • which git
  • Then export the path using the same method as described above, just change that to /usr/local/bin/git

This is the default setting 😉

Adding/Removing Users from ACL in Linux

At times, I come across cases where I need to give access to a group/user to a particular file/directory. This can be done using ACL (Access Control List). Below is how its done 🙂

setfacl -Rdm u:test_user:rwx /opt/app 

Gives RWX access to test_user to /opt/app directory & all its sub-directories.

setfacl -b /opt/app 

Removes ACL entries from /opt/app directory.

setfacl -x u:test_user /opt/app 

Revokes the rights given to test_user to /opt/app directory.

Setting-up Sudo To Allow A User To Edit A Root Editable File

Quite often, we need to allow users to be able to edit files that only root can edit. Obviously we can’t provide them full root access 😉 This situation takes us to sudoers file. Adding a simple line to the sudoers file can make this happen.

test_user ALL=(ALL) NOPASSWD: /bin/vi /etc/profile

Adding this line will enable test_user to edit /etc/profile file without needing to enter password. It just needs to enter sudo vi /etc/profile 🙂