Saturday, November 30, 2013

How to configure db_link on Postgres database to pull data from other database?

I have 2 databases that running on the same database server, but, I have requirement to create a query to join data from the 2 databases. To achieve that, I have to configure db_link in my database server.

Assume the 2 databases are being named as dbA and dbB and the connection are from dbA
dbB User ID: [USER_ID]
dbB Password: [PASSWORD]


To enable db_link, run the command below to enable db_link function
psql -U postgres
postgres=# CREATE EXTENSION dblink
To list the installed extension, type in the command as described below
postgres=# \dx
Below are the sample command that to select data from dbB
SELECT events.* FROM dblink('dbname=dbB user=[USER_ID] password=[PASSWORD]','SELECT title FROM events') AS events(title character varying(255));


Friday, November 8, 2013

How to get your phing to print out timestamp within your timezone?

Try to get the phing scripts below to echo the right timestamp but always unable to do so. The printed timestamp always based on the UTC timestamp.

    <tstamp>
        <format pattern="%Y%m%d_%H%M%S" property="build.time">  
    </format></tstamp>

 <target name="tstamp"> 
  <tstamp>
  <echo>build time = ${build.time}</echo> 
 </tstamp></target>
Initially, I thought this was phing issue, put the locale attributes insides 'format pattern="%Y%m%d_%H%M%S" property="build.time" locale="Asia/Singapore"', but it doesn't solve the issue.
Spent quite a long time to find the root cause, finally, got the clue on what was happening.

Open the php.ini that your PHP is referring to, edit the locale as your current timezone. For other timezone, please refer to http://us1.php.net/manual/en/datetime.configuration.php#ini.date.timezone
date.timezone = Asia/Singapore
Rerun your phing with the same piece of code. Voila! it just work like a charm!

Wednesday, November 6, 2013

How to resolve "Could not open configuration file /etc/httpd/conf/httpd.conf: Permission denied" when start httpd service on RHEL 6?

I encounter this when I transfer (scp) httpd.conf file from my local machine to my new RHEL 6 server. I overwrote the httpd.conf file at /etc/httpd/conf directory and restart httpd service through "service httpd restart". Error message  "Could not open configuration file /etc/httpd/conf/httpd.conf: Permission denied" is prompted.

Type in the command below,
ls -Z
Output as described below is displayed
-rw-rw-r--. user1     user1      unconfined_u:object_r:user_home_t:s0 httpd.conf
-rw-r--r--. root       root       system_u:object_r:httpd_config_t:s0 magic
Steps to resolve this

1. Run the command below to change "unconfined_u:object_r:user_home_t:s0" to "system_u:object_r:httpd_config_t:s0".
chcon system_u:object_r:httpd_config_t:s0 httpd.conf
Once restart httpd service, it should be able to restart the apache service now.

2. For the sake of change the ownership correctly, you can run command below to change the owner
chown root:root httpd.conf
chmod 644 httpd.conf