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 1j02wr-0002KE-PF for pgsql-interfaces@arkaria.postgresql.org; Fri, 07 Feb 2020 12:41:29 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.89) (envelope-from ) id 1j02wo-0002VC-90 for pgsql-interfaces@arkaria.postgresql.org; Fri, 07 Feb 2020 12:41:26 +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 1j01ZC-000634-P2 for pgsql-interfaces@lists.postgresql.org; Fri, 07 Feb 2020 11:12:59 +0000 Received: from mx.shared.smtp.dk ([93.90.117.164]) by makus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1j01Z7-0008Nn-5h for pgsql-interfaces@lists.postgresql.org; Fri, 07 Feb 2020 11:12:57 +0000 Received: from fuji.italianaccent.com (unknown [24.246.154.93]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) (Authenticated sender: mail@italianaccent.com) by mysmtp.eu (Postfix) with ESMTPSA id 48DXhd4mRSz2xN0; Fri, 7 Feb 2020 12:12:49 +0100 (CET) Reply-To: William.B.Clay@acm.org DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=italianaccent.com; s=2019-1; t=1581073967; h=from:from:reply-to:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type:in-reply-to:in-reply-to: references:references; bh=szJb9+vByU4TtVYNRESSPmb5sf1oDLiY1An/xyvv2Bg=; b=eSaAfsDmYi13XA8xcei5vETLfTK3h9ON3Fb0s5U3La9pB5HlvFop4za7LnSdi5l7d3KydS 8ZExYt7xPetkRyc0pwHpjHzBGhOxHyWqpmrmYkU6DujIf0qKIfeNmQJztrepdJO1Wib5e/ GH+zrAcajyJJR1kYas9paqmL9tqmhUz7pqb3/IfSAqxCEIxK2uL/2SAYb5//6xEfyDN3jT /6/yRyiYWsFYGEQKSn9gEg2sCSwNH64TnpemF2XEy8CrTmU6dKS/RoBAgKl8CXDaJmKp6P jCEjau9tAuFXp9KOPecHYhTxUio7qX9etzc+Ak1g3rwt+bMpiIxtnwR7ky1/gQ== Subject: Re: directory name equal database name To: pgsql-interfaces@lists.postgresql.org References: <1580814072.863026304@f532.i.mail.ru> <7029.1580833215@sss.pgh.pa.us> <1581065244.573732834@f438.i.mail.ru> From: "William B. Clay" Cc: squid ward Message-ID: <94b3a8eb-a6e9-cd74-2dcb-54efc97e72be@italianaccent.com> Date: Fri, 7 Feb 2020 12:12:42 +0100 MIME-Version: 1.0 In-Reply-To: <1581065244.573732834@f438.i.mail.ru> Content-Type: multipart/alternative; boundary="------------AB18C3A799EC16B0CCE39258" 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. --------------AB18C3A799EC16B0CCE39258 Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: 8bit On 2/7/20 9:47 AM, squid ward wrote: > I try ask in another way. If I will not rename dabases of existing > PostgreSQL installation, but i configure PostgreSQL from the > beggining, to make directory name equal to database name, or whatever > existing installation or preparation before installation from zero i > cant change this mechanism? ... > As sysadmin i support many companies where i come as remote specialist > from time to time. Sometime in companies happen this: server crashed, > no one configure backup with pg_dump, left only directory with bases > PostgreSQL where inside list of OID databases, over 100 OIDs directory > name that nothing mean. Some databases not critical for work, so can > be connected later, but some databases asking connect very fast. So > when i have 100 databases i even dont know what i need to do for > understanding which one of this databases are «Accounting» database > for example. Squid, As others have explained, you cannot control the filenames PostgreSQL uses to store databases, but you CAN control how databases and tables are mapped onto the host OS filesystem so as to ease DBMS administration, including for space management and backup and recovery. The PostgreSQL way of doing this is through the use of TABLESPACEs, which you can name with any valid PostgreSQL identifier not beginning with "_pg" (e.g., "Accounting").  From PostgreSQL documentation, chapter 22.6: Tablespaces in PostgreSQL allow database administrators to define locations in the file system where the files representing database objects can be stored. Once created, a tablespace can be referred to by name when creating database objects. ... The location [in which the TABLESPACE is created] must be an existing, empty directory that is owned by the PostgreSQL operating system user. All objects subsequently created within the tablespace will be stored in files underneath this directory. The location must not be on removable or transient storage, as the cluster might fail to function if the tablespace is missing or lost. ... Creation of the tablespace itself must be done as a database superuser, but after that you can allow ordinary database users to use it. To do that, grant them the CREATE privilege on it. Tables, indexes, and entire databases can be assigned to particular tablespaces. To do so, a user with the CREATE privilege on a given tablespace must pass the tablespace name as a parameter to the relevant command. See also Section IV.I (Reference/SQL Commands), the "CREATE TABLESPACE" command and the TABLESPACE parameter of, e.g., the CREATE DATABASE command. If you install PostgreSQL and create databases and tables using all defaults, you'll never even notice tablespaces, but to obtain the degree of control you seek, this facility has always been available and is well-documented. --------------AB18C3A799EC16B0CCE39258 Content-Type: text/html; charset=utf-8 Content-Transfer-Encoding: 8bit
On 2/7/20 9:47 AM, squid ward wrote:
I try ask in another way. If I will not rename dabases of existing PostgreSQL installation, but i configure PostgreSQL from the beggining, to make directory name equal to database name, or whatever existing installation or preparation before installation from zero i cant change this mechanism?
...
As sysadmin i support many companies where i come as remote specialist from time to time. Sometime in companies happen this: server crashed, no one configure backup with pg_dump, left only directory with bases PostgreSQL where inside list of OID databases, over 100 OIDs directory name that nothing mean. Some databases not critical for work, so can be connected later, but some databases asking connect very fast. So when i have 100 databases i even dont know what i need to do for understanding which one of this databases are «Accounting» database for example.

Squid,

As others have explained, you cannot control the filenames PostgreSQL uses to store databases, but you CAN control how databases and tables are mapped onto the host OS filesystem so as to ease DBMS administration, including for space management and backup and recovery.

The PostgreSQL way of doing this is through the use of TABLESPACEs, which you can name with any valid PostgreSQL identifier not beginning with "_pg" (e.g., "Accounting").  From PostgreSQL documentation, chapter 22.6:

Tablespaces in PostgreSQL allow database administrators to define locations in the file system where the files representing database objects can be stored. Once created, a tablespace can be referred to by name when creating database objects.

...

The location [in which the TABLESPACE is created] must be an existing, empty directory that is owned by the PostgreSQL operating system user. All objects subsequently created within the tablespace will be stored in files underneath this directory. The location must not be on removable or transient storage, as the cluster might fail to function if the tablespace is missing or lost.

...

Creation of the tablespace itself must be done as a database superuser, but after that you can allow ordinary database users to use it. To do that, grant them the CREATE privilege on it.

Tables, indexes, and entire databases can be assigned to particular tablespaces. To do so, a user with the CREATE privilege on a given tablespace must pass the tablespace name as a parameter to the relevant command.

See also Section IV.I (Reference/SQL Commands), the "CREATE TABLESPACE" command and the TABLESPACE parameter of, e.g., the CREATE DATABASE command.

If you install PostgreSQL and create databases and tables using all defaults, you'll never even notice tablespaces, but to obtain the degree of control you seek, this facility has always been available and is well-documented.

--------------AB18C3A799EC16B0CCE39258--