| From: | Alvaro Herrera <alvherre(at)commandprompt(dot)com> |
|---|---|
| To: | Jose Alberto Sanchez Nieto <albertosanchez(at)hiperusera(dot)es> |
| Cc: | pgsql-es-ayuda(at)postgresql(dot)org |
| Subject: | Re: dudas con schemas |
| Date: | 2008-02-01 20:29:12 |
| Message-ID: | 20080201202912.GW5172@alvh.no-ip.org |
| Views: | Whole Thread | Raw Message | Download mbox | Resend email |
| Thread: | |
| Lists: | pgsql-es-ayuda |
Jose Alberto Sanchez Nieto escribió:
> En resumen amigos: Todas las tablas, indices, funciones, etc las
> generamos inicialmente mediante scripts así que por eso pensamos que si
> creábamos el usuario y se le podía asignar por defecto un schema y sus
> tablespace,
Respuesta breve: luego de crear un usuario y su respectivo schema,
puedes "asignarle" este schema usando
ALTER USER <user> SET search_path = '$user';
A partir de ahi, todos los objetos que ese usuario cree iran a parar a
ese schema. Ejemplo abajo.
Mantengo mi opinion de que hacerlo de esta manera es engorroso. Pero si
quieres hacerlo, se puede.
alvherre=# create user aaa;
CREATE ROLE
alvherre=# create user bbb;
CREATE ROLE
alvherre=# create user ccc;
CREATE ROLE
alvherre=# alter user aaa set search_path = '$user';
ALTER ROLE
alvherre=# alter user bbb set search_path = '$user';
ALTER ROLE
alvherre=# alter user ccc set search_path = '$user';
ALTER ROLE
alvherre=# create schema aaa authorization aaa;
CREATE SCHEMA
alvherre=# create schema bbb authorization bbb;
CREATE SCHEMA
alvherre=# create schema ccc authorization ccc;
CREATE SCHEMA
alvherre=# \q
05:27 perhan: backend 0$ psql alvherre aaa
Welcome to psql 8.2.5, the PostgreSQL interactive terminal.
Type: \copyright for distribution terms
\h for help with SQL commands
\? for help with psql commands
\g or terminate with semicolon to execute query
\q to quit
alvherre=> create table foo ();
CREATE TABLE
alvherre=> \d
List of relations
Schema | Name | Type | Owner
--------+------+-------+-------
aaa | foo | table | aaa
(1 row)
alvherre=> \q
05:28 perhan: backend 0$ psql alvherre bbb
Welcome to psql 8.2.5, the PostgreSQL interactive terminal.
Type: \copyright for distribution terms
\h for help with SQL commands
\? for help with psql commands
\g or terminate with semicolon to execute query
\q to quit
alvherre=> create table foo ();
CREATE TABLE
alvherre=> \d
List of relations
Schema | Name | Type | Owner
--------+------+-------+-------
bbb | foo | table | bbb
(1 row)
--
Alvaro Herrera http://www.CommandPrompt.com/
The PostgreSQL Company - Command Prompt, Inc.
| From | Date | Subject | |
|---|---|---|---|
| Next Message | Espartano | 2008-02-01 22:25:46 | Re: Acceso a PostgreSQL desde C |
| Previous Message | Alvaro Herrera | 2008-02-01 20:14:57 | Re: Cacenlar un insert |