pg.ddx.io pgsql-general@postgresql.org mailing list archive
help / color / mirror / Atom feedPossibilities for optimizing inserts across oracle_fdw foreign data wrapper
5+ messages / 4 participants
[nested] [flat]
* Possibilities for optimizing inserts across oracle_fdw foreign data wrapper
@ 2021-09-19 10:28 Niels Jespersen <NJN@dst.dk>
2021-09-20 01:52 ` Re: Possibilities for optimizing inserts across oracle_fdw foreign data wrapper Mladen Gogala <gogala.mladen@gmail.com>
2021-09-20 13:18 ` Re: Possibilities for optimizing inserts across oracle_fdw foreign data wrapper Laurenz Albe <laurenz.albe@cybertec.at>
0 siblings, 2 replies; 5+ messages in thread
From: Niels Jespersen @ 2021-09-19 10:28 UTC (permalink / raw)
To: pgsql-general
Hello all
We are often using the oracle_fdw to transfer data between Postgres (version 11+) and Oracle (version 18+). It works great.
However I have a task at hand that requires inserting a few billion rows in an Oracle table from a Postgres query.
insert into t_ora (a,b,c)
select a,b,c from t_pg;
This is driven from a plpgsql stored procedure, if that matters.
I want to optimize the running time of this. But I am unsure of which, if any, possibilities there actually is.
Reducing the number of network roundtrips is usually a good way to increase throughput. But, how do I do that?
If I could make the Oracle insert direct load, that would usually also increase throughput. But, is that possible here. There are no constraints defined on the destinaton tables.
Regards Niels Jespersen
^ permalink raw reply [nested|flat] 5+ messages in thread
* Re: Possibilities for optimizing inserts across oracle_fdw foreign data wrapper
2021-09-19 10:28 Possibilities for optimizing inserts across oracle_fdw foreign data wrapper Niels Jespersen <NJN@dst.dk>
@ 2021-09-20 01:52 ` Mladen Gogala <gogala.mladen@gmail.com>
1 sibling, 0 replies; 5+ messages in thread
From: Mladen Gogala @ 2021-09-20 01:52 UTC (permalink / raw)
To: pgsql-general@lists.postgresql.org
On 9/19/21 06:28, Niels Jespersen wrote:
>
> Hello all
>
> We are often using the oracle_fdw to transfer data between Postgres
> (version 11+) and Oracle (version 18+). It works great.
>
> However I have a task at hand that requires inserting a few billion
> rows in an Oracle table from a Postgres query.
>
> insert into t_ora (a,b,c)
>
> select a,b,c from t_pg;
>
> This is driven from a plpgsql stored procedure, if that matters.
>
> I want to optimize the running time of this. But I am unsure of which,
> if any, possibilities there actually is.
>
> Reducing the number of network roundtrips is usually a good way to
> increase throughput. But, how do I do that?
>
> If I could make the Oracle insert direct load, that would usually also
> increase throughput. But, is that possible here. There are no
> constraints defined on the destinaton tables.
>
> Regards Niels Jespersen
>
The problem with oracle_fdw is that the SQL is parsed on the Postgres
side, not on the Oracle side. If it was parsed on the Oracle side, you
could use /*+ APPEND */ hint, which is essentially, a direct insert. You
will have to write a script in one of the scripting languages, which
would utilize the array insert, available with the instant client. Even
Oracle ODBC driver utilizes array insert, as visible from the following
article:
https://dbwhisperer.wordpress.com/2020/11/21/pyodbc-fast_executemany-and-oracle-rdbms/
Unfortunately, the Postgres side of the equation is not particularly
good when using array fetch and does not do particularly well when
trying to cut down on the number of network trips:
https://github.com/mkleehammer/pyodbc/wiki/Driver-support-for-fast_executemany
I would use a script on the Postgres side and then use superior options
provided by SQL*Net. You will need some fancy programming to prevent
waiting on each operation. I would actually write 2 scripts, one reading
data from Postgres, converting it to CSV and then piping it into script
that inserts data into Oracle. That would make the scripts work in
parallel, at least partially. Situations like this are the reason why a
DBA needs to know how to script. So, this is where you start:
https://python.swaroopch.com/
Regards
--
Mladen Gogala
Database Consultant
Tel: (347) 321-1217
https://dbwhisperer.wordpress.com
^ permalink raw reply [nested|flat] 5+ messages in thread
* Re: Possibilities for optimizing inserts across oracle_fdw foreign data wrapper
2021-09-19 10:28 Possibilities for optimizing inserts across oracle_fdw foreign data wrapper Niels Jespersen <NJN@dst.dk>
@ 2021-09-20 13:18 ` Laurenz Albe <laurenz.albe@cybertec.at>
2021-09-20 13:41 ` Re: Possibilities for optimizing inserts across oracle_fdw foreign data wrapper Magnus Hagander <magnus@hagander.net>
1 sibling, 1 reply; 5+ messages in thread
From: Laurenz Albe @ 2021-09-20 13:18 UTC (permalink / raw)
To: Niels Jespersen <NJN@dst.dk>; pgsql-general
On Sun, 2021-09-19 at 10:28 +0000, Niels Jespersen wrote:
> We are often using the oracle_fdw to transfer data between Postgres (version 11+) and Oracle (version 18+). It works great.
>
> However I have a task at hand that requires inserting a few billion rows in an Oracle table from a Postgres query.
>
> insert into t_ora (a,b,c)
> select a,b,c from t_pg;
>
> This is driven from a plpgsql stored procedure, if that matters.
>
> I want to optimize the running time of this. But I am unsure of which, if any, possibilities there actually is.
>
> Reducing the number of network roundtrips is usually a good way to increase throughput. But, how do I do that?
>
> If I could make the Oracle insert direct load, that would usually also increase throughput.
> But, is that possible here. There are no constraints defined on the destinaton tables.
The cause of the bad performance for bulk data modifications is that the FDW API is built
that way: each row INSERTed means a round trip between PostgreSQL and Oracle.
That could be improved by collecting rows and inserting them in bulk on the Oracle
side, but I don't feel like implementing that and complicating the code.
^ permalink raw reply [nested|flat] 5+ messages in thread
* Re: Possibilities for optimizing inserts across oracle_fdw foreign data wrapper
2021-09-19 10:28 Possibilities for optimizing inserts across oracle_fdw foreign data wrapper Niels Jespersen <NJN@dst.dk>
2021-09-20 13:18 ` Re: Possibilities for optimizing inserts across oracle_fdw foreign data wrapper Laurenz Albe <laurenz.albe@cybertec.at>
@ 2021-09-20 13:41 ` Magnus Hagander <magnus@hagander.net>
2021-09-21 07:35 ` Re: Possibilities for optimizing inserts across oracle_fdw foreign data wrapper Laurenz Albe <laurenz.albe@cybertec.at>
0 siblings, 1 reply; 5+ messages in thread
From: Magnus Hagander @ 2021-09-20 13:41 UTC (permalink / raw)
To: Laurenz Albe <laurenz.albe@cybertec.at>; +Cc: Niels Jespersen <NJN@dst.dk>; pgsql-general
On Mon, Sep 20, 2021 at 3:18 PM Laurenz Albe <laurenz.albe@cybertec.at> wrote:
>
> On Sun, 2021-09-19 at 10:28 +0000, Niels Jespersen wrote:
> > We are often using the oracle_fdw to transfer data between Postgres (version 11+) and Oracle (version 18+). It works great.
> >
> > However I have a task at hand that requires inserting a few billion rows in an Oracle table from a Postgres query.
> >
> > insert into t_ora (a,b,c)
> > select a,b,c from t_pg;
> >
> > This is driven from a plpgsql stored procedure, if that matters.
> >
> > I want to optimize the running time of this. But I am unsure of which, if any, possibilities there actually is.
> >
> > Reducing the number of network roundtrips is usually a good way to increase throughput. But, how do I do that?
> >
> > If I could make the Oracle insert direct load, that would usually also increase throughput.
> > But, is that possible here. There are no constraints defined on the destinaton tables.
>
> The cause of the bad performance for bulk data modifications is that the FDW API is built
> that way: each row INSERTed means a round trip between PostgreSQL and Oracle.
>
Just as a note, with PostgreSQL 14 the FDW APIs allow batch insert. It
should be possible to update oracle_fdw to take advantage of that as
well, right?
--
Magnus Hagander
Me: https://www.hagander.net/
Work: https://www.redpill-linpro.com/
^ permalink raw reply [nested|flat] 5+ messages in thread
* Re: Possibilities for optimizing inserts across oracle_fdw foreign data wrapper
2021-09-19 10:28 Possibilities for optimizing inserts across oracle_fdw foreign data wrapper Niels Jespersen <NJN@dst.dk>
2021-09-20 13:18 ` Re: Possibilities for optimizing inserts across oracle_fdw foreign data wrapper Laurenz Albe <laurenz.albe@cybertec.at>
2021-09-20 13:41 ` Re: Possibilities for optimizing inserts across oracle_fdw foreign data wrapper Magnus Hagander <magnus@hagander.net>
@ 2021-09-21 07:35 ` Laurenz Albe <laurenz.albe@cybertec.at>
0 siblings, 0 replies; 5+ messages in thread
From: Laurenz Albe @ 2021-09-21 07:35 UTC (permalink / raw)
To: Magnus Hagander <magnus@hagander.net>; +Cc: Niels Jespersen <NJN@dst.dk>; pgsql-general
On Mon, 2021-09-20 at 15:41 +0200, Magnus Hagander wrote:
> Just as a note, with PostgreSQL 14 the FDW APIs allow batch insert. It
> should be possible to update oracle_fdw to take advantage of that as
> well, right?
Yes. The exercise is more complicated in Oracle, because they don't
support multi-line INSERTs.
Yours,
Laurenz Albe
--
Cybertec | https://www.cybertec-postgresql.com
^ permalink raw reply [nested|flat] 5+ messages in thread
end of thread, other threads:[~2021-09-21 07:35 UTC | newest]
Thread overview: 5+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2021-09-19 10:28 Possibilities for optimizing inserts across oracle_fdw foreign data wrapper Niels Jespersen <NJN@dst.dk>
2021-09-20 01:52 ` Mladen Gogala <gogala.mladen@gmail.com>
2021-09-20 13:18 ` Laurenz Albe <laurenz.albe@cybertec.at>
2021-09-20 13:41 ` Magnus Hagander <magnus@hagander.net>
2021-09-21 07:35 ` Laurenz Albe <laurenz.albe@cybertec.at>
This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox