Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1jlog2-0002WN-JK for pgsql-general@arkaria.postgresql.org; Thu, 18 Jun 2020 07:09:34 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1jlog1-0003zw-GT for pgsql-general@arkaria.postgresql.org; Thu, 18 Jun 2020 07:09:33 +0000 Received: from makus.postgresql.org ([2001:4800:3e1:1::229]) by malur.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1jlog1-0003zo-6Y for pgsql-general@lists.postgresql.org; Thu, 18 Jun 2020 07:09:33 +0000 Received: from mail-pl1-x632.google.com ([2607:f8b0:4864:20::632]) by makus.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.92) (envelope-from ) id 1jlofz-0004Pl-1L for pgsql-general@lists.postgresql.org; Thu, 18 Jun 2020 07:09:32 +0000 Received: by mail-pl1-x632.google.com with SMTP id y18so2066656plr.4 for ; Thu, 18 Jun 2020 00:09:30 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=references:user-agent:from:to:subject:in-reply-to:message-id:date :mime-version; bh=EMLnbxLh6ZWVdDzAx2yXyAvKUdVwPXHGK2OkPD7akJs=; b=s9mLm/EcCPNYNia6vZC1bol4TO2BsAkzHMh608yVll9bonVlwpDlEAxQZK7CgnXgHm 2q1Ulg21EEoe0vM8xCx4KeH6Ibx8550/ftJL+v7R9iaXMei5uoftEpsiLamUi5OYSeA8 vGobSyTuc/huzhzMZyBHSO+EwoqSmSofaWgqSdy6SdzeInTPGHy15MMUw539bdMWtAor 8Psd5w3aEBuHY3sk+UVbhHeSj08MtOz6HkZc2UUeKc7kvYmvXU7aFrSV9OKNgpOSmOEf vy8jNtcjcn9A1tAKLD1inVFj35THNJ/Ao6jf11X7+t1w+tyVwXTBbhHlrZoapcvd9/Qo bkGw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:references:user-agent:from:to:subject :in-reply-to:message-id:date:mime-version; bh=EMLnbxLh6ZWVdDzAx2yXyAvKUdVwPXHGK2OkPD7akJs=; b=eIc0Fq6Cuhugr3AMcUB2teIDfEHxDnOd+waTZeDDcwPMaGiGujRlZjivi3YUbwmKwd g9+F6GqtQx6I1PreEarkTI1nQH7CyyEfnjQCo8w25QBZ1RCPx+t3v+AZlWIkXv2q6xe+ 6iO+/sEi260otdJPC7AeFNSAhaSwMyXMKPai0kixSLZHXJP/sFpq/PlTvMrdrY6ODo6G UrjePmJ2QQyLDBSoDOB7Vpo3XyI+rR6PSAYizaXzouSwcqB47XU5YV+NiTKIE1TIbxri SEUdFonopFtkg7GLP/eMk8Nvv+mt2nbvXQ+ym1A8qMK0JOkO4WEfjGF1mdfW1FivcZTu 5rKg== X-Gm-Message-State: AOAM5333LbAe9zl14b3s60tJPQNsUJ/bAliitqD+K4NqPGFwc5Fy0uNT l8NfF8Qp7e44PAPyZnHAXseg6C75 X-Google-Smtp-Source: ABdhPJwXnJUjBRcwyAw9vfR737M//DDO8+frV/gchRLMz/UzkC+Y/OznM2E96v3byJtdSwfnKKPv5Q== X-Received: by 2002:a17:902:c40c:: with SMTP id k12mr2616608plk.105.1592464169403; Thu, 18 Jun 2020 00:09:29 -0700 (PDT) Received: from tim-desktop (220-235-183-249.dyn.iinet.net.au. [220.235.183.249]) by smtp.gmail.com with ESMTPSA id x3sm1857184pfi.57.2020.06.18.00.09.27 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 18 Jun 2020 00:09:28 -0700 (PDT) References: User-agent: mu4e 1.5.3; emacs 27.0.91 From: Tim Cross To: pgsql-general@lists.postgresql.org Subject: Re: Table partitioning with sequence field in postgresql12 In-reply-to: Message-ID: <87tuz8zw7u.fsf@gmail.com> Date: Thu, 18 Jun 2020 17:09:25 +1000 MIME-Version: 1.0 Content-Type: text/plain List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk Srinivasa T N writes: > Hi, > I have a parent table with one of the field as ""gid" int4 DEFAULT > nextval('"ami_smart_new".aoi_boundary_gid_seq'::regclass)". > > I create child tables which inherit parent and use hash partition. When > I directly insert into child tables, will there be any race condition > causing two child tables getting the same sequence value for gid? > Assuming all inserts use the default e.g. nextval from the same sequence, you won't get duplicates. You could get a duplicate if an insert sets an explicit value for gid of course or if rows in any table were inserted with a gid which was not obtained from the same sequence using nextval i.e. parent and children use same sequence. The sequence is just a counter with the property that no two calls to nextval from that sequence will have the same value. You cannot make any additional assumptions e.g. cannot assume gid values will be inserted in order or there won't be 'gaps ' etc. -- Tim Cross