Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA384:256) (Exim 4.89) (envelope-from ) id 1euJVx-0006R4-9M for pgsql-general@arkaria.postgresql.org; Fri, 09 Mar 2018 15:00:57 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.89) (envelope-from ) id 1euJVv-0003cG-U2 for pgsql-general@arkaria.postgresql.org; Fri, 09 Mar 2018 15:00:55 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA384:256) (Exim 4.89) (envelope-from ) id 1euJVv-0003c7-Ls for pgsql-general@lists.postgresql.org; Fri, 09 Mar 2018 15:00:55 +0000 Received: from mail-qt0-x244.google.com ([2607:f8b0:400d:c0d::244]) by magus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1euJVo-0006nm-AM for pgsql-general@lists.postgresql.org; Fri, 09 Mar 2018 15:00:55 +0000 Received: by mail-qt0-x244.google.com with SMTP id y6so10978037qtm.7 for ; Fri, 09 Mar 2018 07:00:47 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:message-id:mime-version:subject:date:in-reply-to:cc:to :references; bh=bJGGvvCkd8jXCKKFByZCnglzOT59KaqJD/g3trlF5c0=; b=fKcvwogOikwg5HloFlAAMhRXfnX7IHfUJMEdNkUlu0pNLhbkjZ3fryXltdHCWx9Tkx xiKz2c9wJDQjNpkEAXz+Pl0lRO6WQb7MfiN7IV679Vrn9j6FJXFFKDcLUgSC4Wp5GL1v gBxTdDy2Icl2bikiy8B+Sk8ZUIc7oe2Zd1P/gYLZg9YWWcaQFHf6W3fO3CnEq6RPpO7c mEZPzZOOXhCe7EviMif49bdjIjS5MkZOEkkACfN3D7HS3mZ2YwZ69pmSuv5FpU5yoihP ePILGp2OZ7TzXDBYaPY32FfH923pTDkMjvrFdEcMHYz3nFQ9r65W0ohy0Zk22l9TSWni 6HcA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:message-id:mime-version:subject:date :in-reply-to:cc:to:references; bh=bJGGvvCkd8jXCKKFByZCnglzOT59KaqJD/g3trlF5c0=; b=D0toOuR5gn97gycbdV+wju2uqRNvOyADbtLcQpozTAag+cuiOF6mz9bp2HPShMpCbl K+C92E5+1U+MazYHgjlT9bp3fTgrjP7viJuQYE/PUZjJb6Z99Ig/96E3x3KvVxcQkIqa q+rufs49n61gR0Qn5+hjDXrCDuUX4aq5eGC3V8XUhaHXeWJZV96EJi0X4udsRAC/kX/L iq39qMis4zg7OAgbW99TBTf9vYxaldTTbCw1mKs/0zg40XjRZC74+ohbJ7irhT7FtYCw WoHzXz4eJ7i4V4RA5MjrPN/9nBmb/IOzItj5JiXC8nvA60XCYC+PWs+06cZYtYYIDRqa z0Gg== X-Gm-Message-State: AElRT7HU9jMVZWyDrMzgvmYlu/HYj/O+DEsQIc0idyDrNsaz09vKW8Jy zJr6FZLrHTb4LybL47AkWQmmoZJF X-Google-Smtp-Source: AG47ELsvjuCTRGvIuUBuKFQJ4Vk5M6YFqh12InrbvBnb5ZoH/tepTuP44Rle4t6jtWVN4ea1zjovaA== X-Received: by 10.200.58.97 with SMTP id w88mr44327936qte.248.1520607646149; Fri, 09 Mar 2018 07:00:46 -0800 (PST) Received: from [10.0.111.50] (pc-92-113-120-200.cm.vtr.net. [200.120.113.92]) by smtp.gmail.com with ESMTPSA id w201sm624199qkb.52.2018.03.09.07.00.45 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 09 Mar 2018 07:00:45 -0800 (PST) From: Aldrin Martoq Ahumada Message-Id: <1D546CA9-B443-4CE9-A43F-EE70D70DAA9E@gmail.com> Content-Type: multipart/alternative; boundary="Apple-Mail=_1F869B2A-B918-4101-8F3B-58A1BB730C67" Mime-Version: 1.0 (Mac OS X Mail 11.2 \(3445.5.20\)) Subject: Re: Postgresql upgrade to 9.5.12/10.3 changes pg_dump format for cloning schemas Date: Fri, 9 Mar 2018 12:00:43 -0300 In-Reply-To: Cc: pgsql-general@lists.postgresql.org To: Andre Oliveira Freitas References: X-Mailer: Apple Mail (2.3445.5.20) List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk --Apple-Mail=_1F869B2A-B918-4101-8F3B-58A1BB730C67 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset=utf-8 Hi Andre, Yes, here is the issue: = https://github.com/influitive/apartment/issues/532 = It happens if you configured apartment with use_sql=3Dtrue, which means = it clones the schema from pg_dump. My first attempt was to =E2=80=9Cfix=E2= =80=9D the script generated by pg_dump, but I feel it will be a mess. We = solved our issue going back to use_sql=3Dfalse, which is the default = (creates the schema from db/schema.rb). But there is people that have = other requirements, like functions, so the easier way for them is to = keep use_sql and replace strings in the script. Cheers, > On Mar 9, 2018, at 11:51 AM, Andre Oliveira Freitas = wrote: >=20 > Hello Aldrin, >=20 > I'm also using apartment with postgresql 9.6.6, and I don't see any > issue with it. Are you using Apartment::Tenant.create? >=20 > 2018-03-09 10:26 GMT-03:00 Aldrin Martoq Ahumada = : >> Hi, >>=20 >> For a multi tenant system, we are using the following command to = blindly >> clone a schema into another: >> pg_dump -s -x -O -n #{default_tenant} #{dbname} >>=20 >>=20 >> This is done for us by a rails gem, which then feeds that script into = the >> new created schema for the new tenant. >> = https://github.com/influitive/apartment/blob/80a21f2e1cdcbe5b0bd976f88c143= 32657804536/lib/apartment/adapters/postgresql_adapter.rb#L150 >>=20 >>=20 >>=20 >>=20 >> When we upgraded from 9.5.11 to 9.5.12, the format of the dump = changed (it >> now always appends the schema name), so this is broken. We could = patch the >> SQL generated, but that=E2=80=99s not a generic/robust solution. >>=20 >> # pg_dump postgresql 9.5.11 >> SET search_path =3D public, pg_catalog; >> CREATE TABLE ahoy_events ( >> id bigint NOT NULL, >> visit_id integer, >> user_id integer, >> name character varying, >> properties jsonb, >> "time" timestamp without time zone >> ); >>=20 >> # pg_dump postgresql 9.5.12 >> CREATE TABLE public.ahoy_events ( >> id bigint NOT NULL, >> visit_id integer, >> user_id integer, >> name character varying, >> properties jsonb, >> "time" timestamp without time zone >> ); >>=20 >>=20 >>=20 >> Thinking in the long term, how could be the best way to clone a = schema into >> another? >>=20 >>=20 >>=20 >>=20 >> =E2=80=94 >> Aldrin >>=20 >=20 >=20 >=20 > --=20 >=20 > Andr=C3=A9 Luis O. Freitas > System Architect >=20 > Rua do R=C3=B3cio, 220 - Cj. 72 > S=C3=A3o Paulo - SP - 04552-000 > 55 11 4063 4222 >=20 > afreitas@callix.com.br > www.callix.com.br --Apple-Mail=_1F869B2A-B918-4101-8F3B-58A1BB730C67 Content-Transfer-Encoding: quoted-printable Content-Type: text/html; charset=utf-8 Hi = Andre,


It happens if you = configured apartment with use_sql=3Dtrue, which means it clones the = schema from pg_dump. My first attempt was to =E2=80=9Cfix=E2=80=9D the = script generated by pg_dump, but I feel it will be a mess. We solved our = issue going back to use_sql=3Dfalse, which is the default (creates the = schema from db/schema.rb). But there is people that have other = requirements, like functions, so the easier way for them is to keep = use_sql and replace strings in the script.


Cheers,

On Mar 9, 2018, at 11:51 AM, = Andre Oliveira Freitas <afreitas@callixbrasil.com> wrote:

Hello = Aldrin,

I'm also using apartment with = postgresql 9.6.6, and I don't see any
issue with it. Are = you using Apartment::Tenant.create?

2018-03-09 10:26 GMT-03:00 Aldrin Martoq Ahumada <aldrin.martoq@gmail.com>:
Hi,

For a multi = tenant system, we are using the following command to blindly
clone a schema into another:
pg_dump -s -x -O = -n #{default_tenant} #{dbname}


This is done for us by a rails gem, which then feeds that = script into the
new created schema for the new tenant.
https://github.com/influitive/apartment/blob/80a21f2e1cdcbe5b0b= d976f88c14332657804536/lib/apartment/adapters/postgresql_adapter.rb#L150




When we upgraded from 9.5.11 to 9.5.12, the format of the = dump changed (it
now always appends the schema name), so = this is broken. We could patch the
SQL generated, but = that=E2=80=99s not a generic/robust solution.

# pg_dump postgresql 9.5.11
SET search_path =3D = public, pg_catalog;
CREATE TABLE ahoy_events (
   id bigint NOT NULL,
=    visit_id integer,
=    user_id integer,
   name = character varying,
   properties jsonb,
   "time" timestamp without time zone
);

# pg_dump postgresql = 9.5.12
CREATE TABLE public.ahoy_events (
=    id bigint NOT NULL,
=    visit_id integer,
=    user_id integer,
   name = character varying,
   properties jsonb,
   "time" timestamp without time zone
);



Thinking in the long term, how could be the best way to clone = a schema into
another?




=E2=80=94
Aldrin



--

Andr=C3=A9 Luis O. = Freitas
System Architect

Rua = do R=C3=B3cio, 220 - Cj. 72
S=C3=A3o Paulo - SP - = 04552-000
55 11 4063 4222

afreitas@callix.com.br
www.callix.com.br

= --Apple-Mail=_1F869B2A-B918-4101-8F3B-58A1BB730C67--