Pages

Tuesday, July 31, 2012

PostgreSQL Permission Denied

To debug and fix issues related to permission problem with PostgreSQL, especially so when creating tablespaces, the following is useful:
  • Disable firewalls and selinux
  • Check which user is postgres server running as. 
  • Assuming it is running as postgres user, login as user postgres
  • Check "id" to ensure user postgres is part of group postgres 
  • Create the tablespace directory at the required location using mkdir. If you get permission error, fix that and retry. Do not create the directory as root.
The problem should be fixed.

Please leave a comment to share what worked for you to resolve PostgreSQL permission problems. Thanks!





Linux: Which process is listening on a port?


Under various circumstances, like when starting up a server or a service, you may encounter "port already in use" error. Here are different ways to determine which process is using that port.
  • netstat -tulpn | grep <portNumber>
  • fuser <port#>/tcp
  • lsof -i tcp:<port#>

To determine if the commands are available on your system, try:
whereis <command>
e.g. whereis fuser

Once the pid is known for the process using the port, get information on the running process along with its command line:
ps -aux | grep <pid>

Reference

http://www.cyberciti.biz/faq/what-process-has-open-linux-port


Friday, July 20, 2012

OutOfMemoryError: Unable to create new native thread

This post suggests how to fix OutOfMemmory (OOM) error with Java on Linux. There are 2 things to try:


[1] Reduce the stack size in JVM command line and for Linux. RHEL/Oracle Linux default is 8096k to 10240k, while even for most enterprise applications as low as 128k may suffice. HotSpot JDK7 seems to suggest a minimum of 160k. So:
  • Add "-Xss160k" to the JVM commandline
  • Set "ulimit -s 160" from the Linux shell and confirm with "ulimit -a". This setting is per user session. To make it persist for a user, add it to /etc/security/limits.conf
[2] Track the total number of threads on the system:

watch 'ps -efL|wc -l'

Check the system limit:

cat /proc/sys/kernel/pid_max # Usually 32768

If the total number of threads reaches this pid_max, JVM will throw OOM with unable to create new native threads error. 

To fix this issue:

  • Increase the system limit as root:
    echo 65536 > /proc/sys/kernel/pid_max 
  • Or, to persist across reboots, add the following to /etc/sysctl.conf:
    kernel.pid_max = 65536

Thursday, July 19, 2012

Vim - Matching Braces

Matching {}, (), [], /* */, can be very helpful when using vi to read a program code.

In command mode, take your cursor to one of the start/end braces or comment mark and press %, that is, Shift + 5 on most keyboards.

Another useful trick is to highlight the code between the matching tags, and can be achieved simply by:
:noremap % v%

References

http://vim.wikia.com/wiki/Moving_to_matching_braces