<div dir="ltr"><div class="gmail_quote"><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">On 2020-06-15 22:21, Gabriel Ortiz Lour wrote:<br>
> single COPY sql command, which is much faster than single INSERTs<br>
<br>
I agree with COPY on large data sets but how many CDRs are you INSERT batching and at what intervals ?<br></blockquote><div>batch=yes</div><div>size=1000</div><div>time=10</div><div>on my test machine I was with this values, and sometimes it would reach the 10s, sometimes flush because of the 1000 cdrs</div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">
<br>
> Sounds like a small addition for having a much faster CDR insertion<br>
<br>
I think there are several trade-offs w/r/t PostgreSQL COPY vs. INSERT...<br>
<br>
1. COPY FROM "file" is not (as easily) available if PostgreSQL and Asterisk are running on separate servers.<br>
   COPY FROM STDIN is probably the better choice.<br>
<br>
2. COPY stops on first bad record.<br>
<br>
3. COPY disregards table RULEs created using the CREATE RULE PostgreSQL language extension.<br>
   eg. it 'breaks' things like "CREATE RULE rule_insert_cdr ON INSERT TO cdr ..." since that only works on INSERT not COPY.<br>
<br>
So, maybe give the user a choice, with a new option in cdr.conf and/or cdr_pgsql.conf:<br>
<br>
        cdr_batch_prefer_op=insert      ; Default is 'insert'.<br>
                                        ; Other choice includes 'copy'.<br>
                                        ; Falls back to 'insert' if 'copy' fails.<br>
                                        ; Only available on certain backends eg. PostgreSQL.<br></blockquote><div> right, would do</div></div></div>