How to Clone a PostgreSQL database!

At some point in development, you may want to make a copy of your existing development database to play with an unstable new feature. Postgres makes it super trivial to do that by allow us to create a new database by using existing database as a template.

In postgres console, run

=# CREATE DATABASE new_database_name WITH TEMPLATE original_database_name;

Boom!, you got a cloned database named new_database_name.

Credit: Creating a copy of a database in Postgres
I’ve seen a convenient way to make a clone across remote server too. (Haven’t try) How to copy postgres database to another server

Easy step.
Instead of running command in psql, we can use createdb with -T flag like so

$ createdb -T original_database_name new_database_name


How to fix auto-read-only mdadm.

This guide shows you a simple way to fix your mdadm raid based drives which are not syncing or in the auto-read-only mode.

To find the names of your drives which are under auto-read-only mode or not syncing

cat /proc/mdstat

Force the drives to sync.

mdadm --readwrite /dev/md9

Replace md9 with the name of the drive like md127 etc.
server ~ # cat /proc/mdstat
Personalities : [raid0] [raid1] [raid6] [raid5] [raid4] [raid10] [linear] [multipath]
md125 : active (auto-read-only) raid1 sda1[0] sdb1[1]
      192640 blocks [2/2] [UU]

md126 : active raid1 sda5[0] sdb5[1]
      97650944 blocks [2/2] [UU]

md127 : active raid1 sdb2[1] sda2[0]
      97659008 blocks [2/2] [UU]
      [=>...................]  resync =  8.8% (8686848/97659008) finish=64.0min speed=23148K/sec

md128 : active (auto-read-only) raid1 sdb6[1] sda6[0]
      288875200 blocks [2/2] [UU]

Source Info:

CP: max source files number arguments for copy utility


Today we have a problem: We get this error when we try to copy over 32356 file in other folder.
[root@mail]# cp -p office_23\* office\
-bash: /bin/cp: Argument list too long

Solutions: run your command in a loop.

[root@mail]# for file in office_23\*; do cp -p “$file” office\; done

And works very well.

Roundcubemail change default format for date_short

If you want to change time show for mail in roundcubemail you need to do next:

[root@mail ~]# grep date_short /var/www/html/roundcubemail/config/
//$config['date_short'] = 'D H:i';
$config['date_short'] = 'd-m-Y H:i';

But no effect ? Go to Settings —–> Preferences —-> User Interfaces and uncheck “Pretty Dates” like picture below.

Roundcubemail date format

Could not reliably determine the server’s fully qualified domain name Ubuntu?

If you get next error:

Restarting web server apache2
apache2: Could not reliably determine the server's fully qualified domain name, using for ServerName
... waiting apache2:
Could not reliably determine the server's fully qualified domain name, using for ServerName

vi  /etc/apache2/conf.d/fqdn
or vi  /etc/apache2/conf-available/fqdn.conf  ( for Ubuntu 14.04 )
 a2enconf fqdn

Ubuntu server 12.04 LTS with GUI and xRDP.

Some people like GUI interface and some steps show here.

First step is to go comand line interface:

sudo apt-get update
sudo apt-get install ubuntu-desktop

install Gnome 
apt-get install gnome-shell

and reboot

After reboot we need to install xRDP

apt-get install xrdp

root@server-ubuntu-12:~# sysv-rc-conf --list | grep xrdp
xrdp 0:off 1:off 2:on 3:on 4:on 5:on 6:off

How to set locale in Ubuntu / Debian

After a clean Debian/Ubuntu install, I get the following error “LC_ALL to default locale: No such file or directory”.

Answer:  Type the following in terminal to get rid of that error,

sudo apt-get install language-pack-en-base

sudo dpkg-reconfigure locales

Other options it is to run:

 # locale-gen 

You will get

 Generating locales (this might take a while)...
   en_US.UTF-8... done
Generation complete. 


Set WordPress file permissions and FS method

Metod to set file permissions and FS method in wordpress. To allow WordPress to configure wp-config.php during installation, update files during upgrades, and update the .htaccess file for pretty permalinks, give the server write permission on the files.

Change the owner of the wordpress directory and its contents to apache on Centos 7.  Keep the group as staff, a group to which your user account belongs and give write permissions to the group.

First Step.

[root@mailx work]# cd  /var/www/html
[root@mailx html]# chown -R apache.  wordpress-site2
[root@mailx html]# chmod -R g+w   wordpress-site2

Second Step.

Add this to your wp-config.php at the end file.

define(‘FS_METHOD’, ‘direct’);