Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1gwYce-0001Ug-DV for pgsql-general@arkaria.postgresql.org; Wed, 20 Feb 2019 20:37:40 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.89) (envelope-from ) id 1gwYcd-0004rX-4w for pgsql-general@arkaria.postgresql.org; Wed, 20 Feb 2019 20:37:39 +0000 Received: from makus.postgresql.org ([2001:4800:3e1:1::229]) by malur.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1gwYcc-0004rQ-NO for pgsql-general@lists.postgresql.org; Wed, 20 Feb 2019 20:37:38 +0000 Received: from mail-it1-x12c.google.com ([2607:f8b0:4864:20::12c]) by makus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1gwYcZ-0007yZ-Vn for pgsql-general@lists.postgresql.org; Wed, 20 Feb 2019 20:37:37 +0000 Received: by mail-it1-x12c.google.com with SMTP id f10so18609749ita.4 for ; Wed, 20 Feb 2019 12:37:35 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=subject:to:references:from:message-id:date:user-agent:mime-version :in-reply-to:content-language; bh=QQaAsSHH16QLe5CB8IwOcE1IzG7EEmOhOBxT9dXBVw4=; b=EOBliWTf9s+C3a4alUPPaLAbZsEusuOJPl4m/zc5OILZZ0C4VcOShcYQmcbk8cc/IJ Pstbz0tCRzaXG4jhnPayomZpqoQ4CZi7VpvVk5ZQCPr2Gl13K6ojx9sPDwVXR9/Tibxz R8diWYtgS7tfZAvu2xl+EBcMiLrYyZneM1Lfc6YCP98nfhC6rjFo0HbyOC6GyEKIhlgU CLI+7eNcw1rU+CQJ9GQ0DLGhpVaXo71XJDbxO2e1ZXcZSzIxxPZ5qk/81tto1z3x8DoG oP5llpqqj6sxbw9W++J4jmb/uBBYJpAmFv3oGW0a3IyPTiDrzEUn3i5rK856WvmiS0Fi nIvw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:subject:to:references:from:message-id:date :user-agent:mime-version:in-reply-to:content-language; bh=QQaAsSHH16QLe5CB8IwOcE1IzG7EEmOhOBxT9dXBVw4=; b=MHrqwc5QdLD/DdGh3HvP118sTjvyF6y5vp9Zp/M09QsP3RD4l6yrxbDkEYZ0omFj5Z nt7/36uj9gewJk1xmD2w0NuZ1Votvb2WhHVLcNHI5BfohpIKJTc1ZCgblYJdWw0uvBxe 7D7cPlFeEcXSpjDt5JiVJqzIeltDhpyQTQZ45YILz8NEUKihw6FNB8Arlc3YpdmEYMHM 4sJc2WMujEPpPgi07OH6R05EPNCzBfDe4GPPl0RPIOr+AGb/0YLlw4lwq6Lv6Wn9WR07 pgAr7DGCvKRst9ijK7v7Dy/DGCCFYd3APMclwY86V0DQCQfqV4IpcY7DjC6Mrzs9CaoQ elMA== X-Gm-Message-State: AHQUAuYJ57X5Aj3LBYtXDITeWxXFcmQgt2b8lwnmIW5QRjMImbX3jGs3 2Tl1PlYY9yR4OUT+xyMz8sIcw6IP X-Google-Smtp-Source: AHgI3IaD42VVKnST17trINI0a8BMdyH9z011VReUSJ6AV3GBGiDRR4LIhzKxHolcc2CoazvWAUDW2Q== X-Received: by 2002:a24:25ca:: with SMTP id g193mr7748776itg.71.1550695054789; Wed, 20 Feb 2019 12:37:34 -0800 (PST) Received: from [10.22.10.6] ([172.98.67.72]) by smtp.googlemail.com with ESMTPSA id b92sm3111006itd.39.2019.02.20.12.37.33 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 20 Feb 2019 12:37:33 -0800 (PST) Subject: Re: adding more space to the existing 9.6 cluster To: pgsql-general@lists.postgresql.org References: From: Ron Message-ID: Date: Wed, 20 Feb 2019 14:37:32 -0600 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:60.0) Gecko/20100101 Thunderbird/60.4.0 MIME-Version: 1.0 In-Reply-To: Content-Type: multipart/alternative; boundary="------------66747FD4E6F6301B9F362E99" Content-Language: en-US List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk This is a multi-part message in MIME format. --------------66747FD4E6F6301B9F362E99 Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: 8bit On 2/19/19 5:02 PM, Julie Nishimura wrote: > Hello, we are almost out of space on our main data directory, and about to > introduce new directory to our cluster. We cannot use multiple physical > disks as a single volume, so we are thinking about creation new tablespace. > Our current data_directory shows as follows: > /data/postgresql/9.6/main > postgres=# SELECT spcname FROM pg_tablespace; >   spcname > ------------ >  pg_default >  pg_global > (2 rows) > > We also have 36 existing databases on this cluster. > If we add new directory, will it be enough to execute the following > commands in order to force new data there: > CREATE TABLESPACE tablespace01 LOCATION '/data/postgresql/9.6/main01'; > ALTER DATABASE db_name SET TABLESPACE > tablespace01 > > Do I need to repeat it for all our existing databases? Since the command is ALTER DATABASE , it seems that yes you have to do it for all of them.  A simple bash script should knock that out quickly. > Should I change our "template*" dbs as well? If you want *new* databases to automatically go to tablespace01 then alter template1. > Do I need to do something else? Maybe, depending on the size of your databases, and how much down time you can afford, https://www.postgresql.org/docs/9.6/sql-alterdatabase.html "This command physically moves any tables or indexes in the database's old default tablespace to the new tablespace." For example, our multi-TB databases are so big that moving it all at once is unreasonably slow.  And a failure might leave the db is a bad spot.  Thus, I'd move one table at a time, a few per outage. Naturally, YMMV. > Thank you for your advises. -- Angular momentum makes the world go 'round. --------------66747FD4E6F6301B9F362E99 Content-Type: text/html; charset=utf-8 Content-Transfer-Encoding: 8bit On 2/19/19 5:02 PM, Julie Nishimura wrote:
Hello, we are almost out of space on our main data directory, and about to introduce new directory to our cluster. We cannot use multiple physical disks as a single volume, so we are thinking about creation new tablespace.
Our current data_directory shows as follows:
/data/postgresql/9.6/main
postgres=# SELECT spcname FROM pg_tablespace;
  spcname  
------------
 pg_default
 pg_global
(2 rows)

We also have 36 existing databases on this cluster.
If we add new directory, will it be enough to execute the following commands in order to force new data there:
CREATE TABLESPACE tablespace01 LOCATION '/data/postgresql/9.6/main01';
ALTER DATABASE db_name SET TABLESPACE 
tablespace01 

Do I need to repeat it for all our existing databases?

Since the command is ALTER DATABASE <your_user_db>, it seems that yes you have to do it for all of them.  A simple bash script should knock that out quickly.


Should I change our "template*" dbs as well?

If you want new databases to automatically go to tablespace01 then alter template1.

Do I need to do something else?

Maybe, depending on the size of your databases, and how much down time you can afford,


https://www.postgresql.org/docs/9.6/sql-alterdatabase.html "This command physically moves any tables or indexes in the database's old default tablespace to the new tablespace."

For example, our multi-TB databases are so big that moving it all at once is unreasonably slow.  And a failure might leave the db is a bad spot.  Thus, I'd move one table at a time, a few per outage.

Naturally, YMMV.

Thank you for your advises.



--
Angular momentum makes the world go 'round.
--------------66747FD4E6F6301B9F362E99--