|  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #75705 pg_field_type() slow and consumes CPU on a large database
Submitted: 2017-12-19 13:01 UTC Modified: 2022-10-10 08:06 UTC
Avg. Score:5.0 ± 0.0
Reproduced:2 of 2 (100.0%)
Same Version:1 (50.0%)
Same OS:1 (50.0%)
From: dmitry dot kunilov at gmail dot com Assigned: cmb (profile)
Status: Duplicate Package: PostgreSQL related
PHP Version: 7.2.0 OS:
Private report: No CVE-ID: None
View Add Comment Developer Edit
Welcome! If you don't have a Git account, you can't do anything here.
You can add a comment by following this link or if you reported this bug, you can edit this bug over here.
Block user comment
Status: Assign to:
Bug Type:
From: dmitry dot kunilov at gmail dot com
New email:
PHP Version: OS:


 [2017-12-19 13:01 UTC] dmitry dot kunilov at gmail dot com
Our database has around 25K tables. Whenever a PHP script does a first call to pg_field_type(), it consumes a lot of CPU, memory and network traffic.
This is reproducible with all PHP versions from 5 to 7.2

The problem was narrowed down to the following query performed from ext/pgsql/pgsql.c get_field_name():

select oid,typname from pg_type

As postgresql defines several types for each table in the database, the above query produces over 76K rows on our system. All of those are put into a hashmap by get_field_name().

Obviously, rowset types present in pg_type table cannot be used as field types, and have to be excluded from the query.


Add a Patch

Pull Requests

Add a Pull Request


AllCommentsChangesGit/SVN commitsRelated reports
 [2022-10-10 08:06 UTC]
-Status: Open +Status: Duplicate -Assigned To: +Assigned To: cmb
 [2022-10-10 08:06 UTC]
Closing as duplicate of
PHP Copyright © 2001-2023 The PHP Group
All rights reserved.
Last updated: Thu Feb 02 03:05:54 2023 UTC