Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1ueWWg-00AiPX-Mg for pgsql-general@arkaria.postgresql.org; Wed, 23 Jul 2025 10:16:43 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.94.2) (envelope-from ) id 1ueWWf-001U37-CH for pgsql-general@arkaria.postgresql.org; Wed, 23 Jul 2025 10:16:41 +0000 Received: from makus.postgresql.org ([2001:4800:3e1:1::229]) by malur.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1ueWWf-001U2z-0o for pgsql-general@lists.postgresql.org; Wed, 23 Jul 2025 10:16:41 +0000 Received: from mail-ed1-x52f.google.com ([2a00:1450:4864:20::52f]) by makus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 (Exim 4.96) (envelope-from ) id 1ueWWd-000Msb-1w for pgsql-general@postgresql.org; Wed, 23 Jul 2025 10:16:40 +0000 Received: by mail-ed1-x52f.google.com with SMTP id 4fb4d7f45d1cf-60707b740a6so9271731a12.0 for ; Wed, 23 Jul 2025 03:16:39 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=cybertec.at; s=google; t=1753265798; x=1753870598; darn=postgresql.org; h=mime-version:user-agent:content-transfer-encoding:references :in-reply-to:date:to:from:subject:message-id:from:to:cc:subject:date :message-id:reply-to; bh=NO6cgAP83tbGU+7ZDUmi5kF/NoEGu3XFmBvkBklTvM8=; b=omYUQK3I5Kl2P6z9rzczh/tLZVlU0owi0GbDfaRaemQKaTSq3wtwfm+kKwCFy83+uk uSk58socGinIFZGPURwJ5JfaPSRAwfLmGC+/UtVuOky3/JclSwh63V+ICP5N8fAx8DgZ Rx2xwF0yvQBeDSbeP6KD+yDpQfwuw4/IjtKE176oOJs+yzLU9uxzTiK3HvD1Bbe1Qmwi Z6bwhZyH0XzXy0Zb36tGLlTf1kRuYMlMhyRDW2mHd9/FgF4FEJCuH4r3I33DJTDV+4CP smK1tdK/olffX6Eck/IUgoByFX5pO+kfmZYlVqfU4SPt0XAiRIsopuOVSX2MEq+auSPN GXVA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1753265798; x=1753870598; h=mime-version:user-agent:content-transfer-encoding:references :in-reply-to:date:to:from:subject:message-id:x-gm-message-state:from :to:cc:subject:date:message-id:reply-to; bh=NO6cgAP83tbGU+7ZDUmi5kF/NoEGu3XFmBvkBklTvM8=; b=Ny7hWOUrfnMI+xxdyUoru1rYPeZxdEhH6fdSTWHTXdpOR+4J9R9pB12+FlHYuXVAYZ Mn3epLUHKQDagfLxd6WKoS4gfEIcWVs2MLW2a0pP/yBWDKY8fPtsM9r+YlQbmaUeBBz9 FUI542OzQTSCDVhDA5GNL1V6R8wsDpdvCivnmGfqkK1sJzZrWPwgXrDO2jvqBvdarjlp WXGfik5SBcUu5vrmwAb5HEMI9eWm7TLe9amwL+CrrAcBobgP/5WrQfldzUItdv5NWK9O iqTEmZWmYh2kpQc7U5LtevsZADpZjD6aMiismzszsmZeqHBSCc9kgxJE6szPX2cPu7t7 BTOQ== X-Forwarded-Encrypted: i=1; AJvYcCWoiN36haqHQQZfrGt2ILTwdE8udV2L/K2rLEAmBOfZaupftdI+6iZB4pc60Q541bLk9b/MuIFhHMFxUiA1@postgresql.org X-Gm-Message-State: AOJu0YxokZivwqP3sl/b85UTcnJo4kUo4y0Wxyq4fmBMAak6Jk8tuwyT wo6dxfxNKflBTySZJ3mGdshaaRkw5cr31ZZsNmI6eMarZm/5aM2Yi+1tt9yZBPSjb7/Fin8HmMI TZO1a X-Gm-Gg: ASbGncsGsczxSBwVf2rAmd5p4YZaiAYbKK9NPIdl/4kRds54UlPKIEbcbqlO8+mzG8v jZMDiTG1itN5tVkAZ+zxIXxvQ9EQJ4aqoZPuMURPm85CaNXDyuKBukqhHwnWz6M6wC6RzvQ2M1T HLTYWI69uUILqwAb09y8O1Fj6ci1qPfcqVUpcAM93oW21pNtWdOFrWthXS7zNlw/CgZxkH4QdWy lazzFDiPfhiKgwCH/djY3vYrRRJxTKnVacrGOBqMtbzmhLlbdLYrE3BypCCwTdoX/8hGwpl6HFf WLwKaiPrOIr5HdRSp8C2V4GclZ2j6Bnc/KlqHcCClhGAHOlxoGlqZGR7zFB2NOy6u8G3qG7NPUy thu+NKDbBTF6z/fXkmKyjIpm4PXVZOoq1iirtfuJnTKs7WQKUrJo= X-Google-Smtp-Source: AGHT+IGxiX39dtypd3bVnNCXkA34XBGaHULFqn8/mzbCYmdww+KiZ7H1Vhv7VN44a2k9Hqly4f3ikw== X-Received: by 2002:a05:6402:1e96:b0:612:9fee:8a55 with SMTP id 4fb4d7f45d1cf-6149b45d535mr2160438a12.3.1753265797666; Wed, 23 Jul 2025 03:16:37 -0700 (PDT) Received: from laurenz.albe-K4N0CV00F97414D ([2001:871:5e:e86d:8078:8faa:e2ff:22f7]) by smtp.gmail.com with ESMTPSA id 4fb4d7f45d1cf-612c8f335e9sm8197511a12.17.2025.07.23.03.16.36 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 23 Jul 2025 03:16:36 -0700 (PDT) Message-ID: Subject: Re: Is there any limit on the number of rows to import using copy command From: Laurenz Albe To: "sivapostgres@yahoo.com" , Pgsql-general Date: Wed, 23 Jul 2025 12:16:35 +0200 In-Reply-To: <1453510076.1900935.1753260637232@mail.yahoo.com> References: <1453510076.1900935.1753260637232.ref@mail.yahoo.com> <1453510076.1900935.1753260637232@mail.yahoo.com> Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable User-Agent: Evolution 3.56.2 (3.56.2-1.fc42) MIME-Version: 1.0 List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk On Wed, 2025-07-23 at 08:50 +0000, sivapostgres@yahoo.com wrote: > Tried in PostgreSQL 11.11 , PostgreSQL 15.2 in Windows 10 Both of these choices are unsavory. Don't use the unsupported v11, and use 15.13 with v15. > Here we try to transfer data from one database to another (remote) databa= se.=C2=A0 >=20 > Tables do have records ranging from 85000 to 3600000 along with smaller s= ized tables. > No issues while transferring smaller sized tables. >=20 > I here take one particular table [table1] which has 85000 records. > The table got Primary Key, Foreign Key(s), Triggers.=C2=A0 Trigger update= s another table [table2] > Table2 have 2 triggers, one to arrive a closing value and other to delete= , if the closing value is zero. >=20 > 1.=C2=A0 Transfer the data from source database to a csv file.=C2=A0 8500= 0 records transferred. No issues. > 2.=C2=A0 Transfer the file to the remote location.=C2=A0 No issues. > 3.=C2=A0 Transfer the contents of the file to the table using Copy From c= ommand. - Fails when try to transfer all the 85000 records at once.=C2=A0= =C2=A0 >=20 > Copy from command is >=20 > Copy public.table1 From 'E:\temp\file1.csv' (FORMAT CSV, DELIMITER ',', H= EADER TRUE) >=20 > The above command succeeds, when > 1.=C2=A0 The trigger in Table1 is disabled with all other constraints on. > 2.=C2=A0 The no. of rows is within 16000 or less, with Trigger enabled.= =C2=A0 We haven't tried with higher no of rows. >=20 > The above command goes on infinite loop, when > 1.=C2=A0 We try to transfer all 85000 rows at once, with Trigger and othe= r constraints in table1 enabled. > We waited for 1.5 hrs first time and 2.5 hrs second time before canc= elling the operation. >=20 > I read in the documentation that the fastest way to transfer data is to u= se Copy command. > And I couldn't find any limit in transferring data using that command. > One could easily transfer millions of rows using this command. There is no limit for the number of rows that get created by a single COPY. You should research why processing fails for higher row counts: - Are there any messages on the client or the server side? - Is the backend process on the server busy (consuming CPU) when processing= hangs? - Do you see locks or other wait events in "pg_stat_activity"? > Here are the triggers. >=20 > Trigger function, which is called from Table1 on After Insert, Update, De= lete One thing you could try is a BEFORE trigger. That should work the same, un= less there are foreign key constraints. Do you see high memory usage or paging = for the backend process when the COPY hangs? > [...] > If (Select Count(*) > =C2=A0From=C2=A0 =C2=A0table2 > =C2=A0WHERE=C2=A0 companycode =3D company_code > =C2=A0AND=C2=A0 =C2=A0 branchcode=C2=A0 =3D branch_code > =C2=A0AND=C2=A0 =C2=A0 locationfk=C2=A0 =3D location_fk > =C2=A0AND=C2=A0 =C2=A0 barcode=C2=A0 =C2=A0 =C2=A0=3D variety_code ) > 0 = Then > [...] That may well be slow, particularly without a matching index. A better way to write that would be IF EXISTS (SELECT 1 FROM table2 WHERE ...) because that can stop processing after the first match. It still needs an index for fast processing. Yours, Laurenz Albe