Re: Bulk Update

From: Erkan Durmuş <derkan(at)gmail(dot)com>
To: Fırat Güleç <firat(dot)gulec(at)hepsiexpress(dot)com>, "N(dot) Can KIRIK" <can(at)epati(dot)com(dot)tr>, M(dot)Atıf CEYLAN <mehmet(at)atifceylan(dot)com>, pgsql-tr-genel(at)postgresql(dot)org
Subject: Re: Bulk Update
Date: 2017-09-30 14:25:23
Message-ID: 9d8740ce-70fc-05db-f41c-87a59f268c80@gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: Postg롤 토토SQL :

|WITHOUT HOLD|ile açılan cursor'ü sadece SQL komut satırında
kullanabiliyormuşuz, bu durumda PL/pgSQL içinde bu seçenek geçersiz
</docs/9.1/static/sql-declare.html>.

*Note:*This page describes usage of cursors at the SQL command
level. If you are trying to use cursors inside a PL/pgSQL function,
the rules are different

Onun yerine ya tek SQL ile yapacaksınız veya extension üzerinden,
örneğin pg_background
<https://github.com/vibhorkum/pg_background>kullanabilirsiniz. Örnek
kullanım için bu yazıya
<http://blog.dalibo.com/2016/08/19/Autonoumous_transactions_support_in_PostgreSQL.html>bakabilirsiniz.

On 30-09-2017 15:31, Fırat Güleç wrote:
>
> Merhabalar,
>
> Dönüşleriniz için çok teşekkür ederim.
>
> Bundan beş ay önce bir çalışanımızın haber vermeden yaptığı tek
> satırlık update (Yaklaşık 5 milyon kayıt) tamamlanmadan, database
> diğer requestlere cevap veremez hale geldi. O zamanlar PL/SQL’de yeni
> olduğumdan dolayı update cümleciklerinin arasına commit koymadığından
> dolayı bu problem yaşadığımızı düşünmüştüm. O yüzden aynı duruma
> düşmemek için bu kadar kayıt’ın update’ini bir sql’de yapmak istemiyorum.
>
> @M.Atıf CEYLAN, evet tam olarak istediğim bu, bütün update’i problem
> yaşamadan 100 kayıtta bir veya her kayıttan sonra da olabilir, commit
> yapmış gibi, dışarıya görünür kılmak istiyorum. Bulk update’den dolayı
> temp, memory veya file’in şişmesini istemiyorum.
>
> @N. Can KIRIK, yukarıda belirttiğim gibi daha önceki tecrübemden
> dolayı tek sql kullanmaya sıcak bakmıyorum.
>
> @Erkan Durmuş , tam anlayamadığım bir nokta var, cursor’i with hold
> ile tanımladığımız zaman, her bir transaction’dan sonra mı commit
> koyuyor. Yani 3 milyon tane kayıt update edicek isek, 3 milyon commit
> mi demek?
>
> İyi çalışmalar.
>
> *From:*pgsql-tr-genel-owner(at)postgresql(dot)org
> <mailto:pgsql-tr-genel-owner(at)postgresql(dot)org>
> [mailto:pgsql-tr-genel-owner(at)postgresql(dot)org
> <mailto:pgsql-tr-genel-owner(at)postgresql(dot)org>] *On Behalf Of *Erkan Durmus
> *Sent:* Saturday, September 30, 2017 10:39 AM
> *To:* pgsql-tr-genel(at)postgresql(dot)org <mailto:pgsql-tr-genel(at)postgresql(dot)org>
> *Subject:* Re: [pgsql-tr-genel] Bulk Update
>
> Eğer |COMMIT|etmez iseniz ORACLE'da |ORA-1562 FAILED TO EXTEND
> ROLLBACK SEGMENT|hatası alırsınız. Fakat PostgreSQL'in işleyişi biraz
> farklı, rollback segment yok, o yüzden de extend edilmesi gereken
> birproblem de olmuyor (Onun yerine |VACUUM|işlemlerimiz kalıyor
> sonrası için :-)). Şunu okuyunuz:
>
> It is interesting how the dynamic allocation of disk space is used
> for the storage and processing of records within tables. The files
> that represent the table grow as the table grows. It also grows
> with transactions that are performed against it. In Oracle there
> is a concept of rollback or undo segments that hold the
> information for rolling back a transaction. In PostgreSQL the data
> is stored within the file that represents the table. So when
> deletes and updates are performed on a table, the file that
> represents the object will contain the previous data. This space
> gets reused but to force recovery of used space, a maintenance
> process called /vacuum/must be executed.
>
> Onun için bulk update'i tek SQL ile yapabilirsiniz. Ama yine de
> |COMMIT|'i transaction içinde yapmanız gerekiyorsa, cursor'u |WITH
> HOLD|ile tanımlayınız
> </docs/current/static/sql-declare.html>.
>
> |WITH HOLD|specifies that the cursor can continue to be used after
> the transaction that created it successfully commits. |WITHOUT
> HOLD|specifies that the cursor cannot be used outside of the
> transaction that created it. If neither |WITHOUT HOLD|nor |WITH
> HOLD|is specified, |WITHOUT HOLD|is the default.
>
> On 29-09-2017 10:03, Fırat Güleç wrote:
>
> Merhabalar,
>
> Bir konuda yardımınız ihtiyacım var. Postgresql 9.5.8 versiyonunu
> kullanıyoruz. Bulk bir update yapmaya ihtiyacımız oldu, yaklaşık
> 4.5 milyonluk bir kayıt. Oracle’da begin end’in arasına commit
> koyabiliyorduk. Fakat Postgresql’de bunu yapamadığımızı farkına
> vardık. 100 kayıt update ettikten sonra commit yapmak istiyoruz.
> Bu gibi ihtiyaçlar için Postgresql’de nasıl bir çözüm
> kullanıyorsunuz?
>
> İyi çalışmalar.
>
> Örnek kod:
>
> *DECLARE
> **c_delivery **RECORD**;
>     cur_rad CURSOR (**x_address_id **BIGINT**, **x_receiver_id
> **BIGINT**) FOR SELECT */*/*
>                         FROM **receiver_address**
>                                                                   
> WHERE **receiver_id**= **x_receiver_id**AND
> **address_id**= **x_address_id**;
> **c_rad **RECORD**;
> BEGIN
>   FOR **c_delivery**IN SELECT */*/*FROM **delivery**WHERE
> recipient_address_id is NULL LIMIT **p_record_cnt**LOOP
>
>     OPEN
> cur_rad(**c_delivery**.**receiver_address_id**,**c_delivery**.**receiver_id**);
>     FETCH cur_rad INTO **c_rad**;
>     IF **c_rad**.id IS NOT NULL
>     THEN
>       UPDATE ***********SET recipient_address_id = **c_rad**.id
> WHERE **id**= **c_delivery**.**id**;
>       UPDATE ****************SET recipient_address_id =
> **c_rad**.id WHERE **delivery_id**= **c_delivery**.**id**;
>     END IF;
>     CLOSE cur_rad;
>   END LOOP;
> END;*
>
> *FIRAT GÜLEÇ***
> Veritabanı Yöneticisi
> firat(dot)gulec(at)hepsiexpress(dot)com <mailto:firat(dot)gulec(at)hepsiexpress(dot)com>
>
> *M:*0 532 210 57 18
> İnönü Mh. Mimar Sinan Cd. No:3 Güzeller Org.San.Bölg. GEBZE / KOCAELİ
>
> ------------------------------------------------------------------------
>
> Inline image 1
>

In response to

Browse pgsql-tr-genel by date

  From Date Subject
Next Message Devrim Gündüz 2017-10-01 02:43:25 Re: Bulk Update
Previous Message Samed YILDIRIM 2017-09-30 13:00:20 Re: Bulk Update