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 1l0MQJ-0007xo-Kt for pgsql-general@arkaria.postgresql.org; Fri, 15 Jan 2021 10:33:44 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1l0MQI-0004oU-Jb for pgsql-general@arkaria.postgresql.org; Fri, 15 Jan 2021 10:33:42 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1l0MQI-0004oN-5P for pgsql-general@lists.postgresql.org; Fri, 15 Jan 2021 10:33:42 +0000 Received: from srvimsva2.dst.dk ([91.208.143.64]) by magus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1l0MQG-0008F3-0L for pgsql-general@postgresql.org; Fri, 15 Jan 2021 10:33:41 +0000 Received: from srvimsva2.dst.dk (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id BB60F104067 for ; Fri, 15 Jan 2021 11:33:38 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=dst.dk; s=dmz20180119; t=1610706818; bh=XrRzJF/CGaaaX2AC1IwOOtEkT69m6MPSTcyTORS3MDM=; h=From:To:Date; b=Jmhs7Amp1Mwo0hN9ObsqPip/oxPIGWhliybTOZ9xB7M+D8kmWoVei6SZ9q3rrKc0p NKFzaNpl6xNVuTr9Bbf0owlHPpM9+H8sWfSbsI1/RKhFA7luO7jfMtkfWWhiGoezAZ xgwxBNUWfyQU1Os/XTzgcwNm+fBRnGQMSR9rky1I= Received: from srvimsva2.dst.dk (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id AED7E104060 for ; Fri, 15 Jan 2021 11:33:38 +0100 (CET) Received: from Sepo.dst.dk (unknown [192.168.64.12]) by srvimsva2.dst.dk (Postfix) with ESMTP for ; Fri, 15 Jan 2021 11:33:38 +0100 (CET) Received: from srvexc9.dst.local ([172.30.32.49]) by Sepo.dst.dk (JAMES SMTP Server 2.3.2-1) with SMTP ID 566 for ; Fri, 15 Jan 2021 11:33:38 +0100 (CET) Received: from srvexc8.dst.local (172.30.32.48) by srvexc9.dst.local (172.30.32.49) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2106.2; Fri, 15 Jan 2021 11:33:38 +0100 Received: from srvexc8.dst.local ([fe80::9df8:5de5:1bf2:8b3b]) by srvexc8.dst.local ([fe80::9df8:5de5:1bf2:8b3b%2]) with mapi id 15.01.2106.002; Fri, 15 Jan 2021 11:33:38 +0100 From: Niels Jespersen To: "pgsql-general@postgresql.org" Subject: time-based range partitioning and truncate/delete different timezones Thread-Topic: time-based range partitioning and truncate/delete different timezones Thread-Index: AdbrHjnIeQHBytzwSNyFxTTG8OyclA== Date: Fri, 15 Jan 2021 10:33:38 +0000 Message-ID: <97f889bbea084fdb8cfd94e73ab1358d@dst.dk> Accept-Language: da-DK, en-US Content-Language: da-DK X-MS-Has-Attach: X-MS-TNEF-Correlator: x-originating-ip: [172.30.33.38] Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 X-TM-AS-GCONF: 00 List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk Hi all I need ideas regarding a way to design an insert, truncate/delete, and rein= sert process on data that is in UTC and database range partitions that are = in the Europe/Brussels time zone. Therefore, any input is welcome.=20 The issue at hand is this. We receive daily file deliveries of time-based m= easurements. The files are zipped csv's. A file covers a UTC-day (e.g. 2021= -01-15 00:00:00+00 to 2021-01-15 23:59:59+00). About 100 million rows a day= .=20 Loaded by Python into a Postgres 12 database table, range-partitioned on Eu= rope/Brussels days. Database session in UTC, since timestamps in data has n= o time zone indicator. Most rows hit the same partition, but the last hour = (this time of year, in the summer it is 2 hours) hits the next partition. S= treamed directly from zip by psycopg2.cursor.copy_expert. Works perfect.=20 Then analysis on the data can proceed. Aggregating stuff on daily or monthl= y basis. This works fine since data is partitioned on our local time zone a= nd we want aggregates on the same time zone.=20 Then, two weeks later a better delivery comes in covering the same UTC-peri= od. Data quality is better, so we want to replace the old data with the new= data. If data were partitioned on the same time zone boundary as the file = covers, then a truncate partition, insert new data would be the obvious sol= ution. That is no good, since the truncate will wipe an hour too much on on= e end and an hour too little on the other end.=20 So what is a better solution? Delete from t where t.timecolumn between a an= d b, and reinsert the new data. My instinct says no, but I cannot really th= ink of a good alternative. It is 100 million rows with 5 or 6 numeric colum= ns. Regards Niels Jespersen