I have a little problem connecting the Postgres server from php. I just started working with Postgres + PHP combos, and I realized that establishing a connection is very slow. A simple connection usually takes 1 s, and sometimes more than 2 seconds. And this is only a development server, so there is no real traffic. Well, the server is not the best, but connecting to MySQL is much faster.
After connecting, everything goes well, each request works as I expect. The application’s run time is about 10%, and the connection is about 90%. Really strange, because with the mysql database level it is very fast.
What could be the problem?
I tried with PDO, pg_pconnect, pg_connect, but each time the result is the same.
Could this be a Postgres configuration error? But requests are fast, only the connection is slow. I have no idea.
PG: PostgreSQL 8.3.9
PHP: 5.2.6
Thank you in advance!
Configuration:
#------------------------------------------------------------------------------
# CONNECTIONS AND AUTHENTICATION
#------------------------------------------------------------------------------
# - Connection Settings -
#listen_addresses = 'localhost'
# comma-separated list of addresses;
# defaults to 'localhost', '*' = all
# (change requires restart)
port = 5432 # (change requires restart)
max_connections = 100 # (change requires restart)
# Note: Increasing max_connections costs ~400 bytes of shared memory per
# connection slot, plus lock space (see max_locks_per_transaction). You might
# also need to raise shared_buffers to support more connections.
#superuser_reserved_connections = 3
unix_socket_directory = '/var/run/postgresql' # (change requires restart)
#unix_socket_group = ''
#unix_socket_permissions = 0777
# (change requires restart)
#bonjour_name = ''
# (change requires restart)
# - Security and Authentication -
#authentication_timeout = 1min
ssl = true # (change requires restart)
#ssl_ciphers = 'ALL:!ADH:!LOW:!EXP:!MD5:@STRENGTH'
# (change requires restart)
#password_encryption = on
#db_user_namespace = off
# Kerberos and GSSAPI
#krb_server_keyfile = ''
#krb_srvname = 'postgres'
#krb_server_hostname = ''
# (change requires restart, Kerberos only)
#krb_caseins_users = off
#krb_realm = ''
# - TCP Keepalives -
# see "man 7 tcp" for details
#tcp_keepalives_idle = 0
# 0 selects the system default
#tcp_keepalives_interval = 0
# 0 selects the system default
#tcp_keepalives_count = 0
# 0 selects the system default
#------------------------------------------------------------------------------
# RESOURCE USAGE (except WAL)
#------------------------------------------------------------------------------
# - Memory -
shared_buffers = 24MB # min 128kB or max_connections*16kB
# (change requires restart)
#temp_buffers = 8MB
#max_prepared_transactions = 5
# (change requires restart)
# Note: Increasing max_prepared_transactions costs ~600 bytes of shared memory
# per transaction slot, plus lock space (see max_locks_per_transaction).
#work_mem = 1MB
#maintenance_work_mem = 16MB
#max_stack_depth = 2MB
# - Free Space Map -
max_fsm_pages = 153600 # min max_fsm_relations*16, 6 bytes each
# (change requires restart)
#max_fsm_relations = 1000
# (change requires restart)
# - Kernel Resource Usage -
#max_files_per_process = 1000
# (change requires restart)
#shared_preload_libraries = ''
# - Cost-Based Vacuum Delay -
#vacuum_cost_delay = 0
#vacuum_cost_page_hit = 1
#vacuum_cost_page_miss = 10
#vacuum_cost_page_dirty = 20
#vacuum_cost_limit = 200
# - Background Writer -
#bgwriter_delay = 200ms
#bgwriter_lru_maxpages = 100
#bgwriter_lru_multiplier = 2.0
source
share