0

I am new to the server part of ubuntu. I am setting up a server with ubuntu 14.04 LTS OS installed. I have two 1TB sata disks and two 2TB sata disks(configured with RAID 1 for both). I am using the 1TB ones for the OS and also other things, but for my database I want to use 2TB disks.

I have installed postgresql on my server, but I want to have all the data of the database to get stored on the 2TB one.

So I want some assistance in how to do that. I mean how to set the home or the data_directory of my postgresql database so that the data gets stored on the 2TB one directly.

I would appreciate if the help is given starting from mount point.

Thanks in advance

Vishal
  • 1

2 Answers2

2

Actually this is quite simple. All you have to do is specify a path when creating a database cluster. This comes from the postgresql documentation. The command to create a new pg cluster is initdb and looks like this:

initdb [option...] [--pgdata | -D] directory

According to the documentation,initdb will create the specified directory unless it has no privileges to write to the target location. To be safe you can create it as root and then change ownership to postgres system user. In my system (used for development) I created a directory under /home (on a raid1 array) that belongs to postgres and ran the initdb against that directory.

cd /home sudo mkdir postgres sudo chown postgres:postgres postgres initdb [your db creation options here] --pgdata /home/postgres

Now you can start the postgresql server specifying the pgdata directory. For example,

pg_ctl start -D /home/postgres

will start a server instance that makes uses of your specified directory. If a server instance is already running you may wish to replace start with restart. This will bring down the running server and start it with the new options.

On a side note, as you may have already guessed, it is possible to have multiple instances of the server running at the same time (on different ports of course), each managing a separate cluster (ie physical path).

hmayag
  • 2,246
  • 5
  • 21
  • 23
1

I'm not sure where postgres stores its data, I would think /var/lib/postgresql/. If you want to use the 2tb exclusively for postgres data, you could do the following: (I don't have postgres running atm, please check paths and names. This works for any service type though, so as well on postgres.)

  • Stop postgres sudo service postgres stop
  • mv data dir: sudo mv /var/lib/postgresql /var/lib/postgresql.bak
  • sudo mkdir /var/lib/postgresql
  • create a filesystem and mount the new drive to /var/lib/postgresql
  • change owner and group to postgres and change access rights (chown and chmod, you can check the old settings from ls -la /var/lib/postgresql.bak)
  • Copy the postgres data back: cp -ra /var/lib/postgresql.bak/. /var/lib/postgresql
  • restart postgres: service postgres start
Basil A
  • 103