Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Segmentation fault when using specific names for tables #1124

Closed
yurifari opened this issue Aug 8, 2023 · 6 comments · Fixed by #1125
Closed

Segmentation fault when using specific names for tables #1124

yurifari opened this issue Aug 8, 2023 · 6 comments · Fixed by #1125
Labels
bug Something isn't working

Comments

@yurifari
Copy link

yurifari commented Aug 8, 2023

Describe the bug
When querying a table which is using a PostgreSQL System Information Functions and Operators name, the server hits a segmentation fault and crashes.

For example, querying a table called user, will result in a segmentation fault. This because user is a system function.
The same behaviour will be triggered using any other system function name, e.g.: current_user.

Workarounds
Surrounding the table name with quotes will prevent the issue from happening, e.g.: SELECT * FROM "user"
Specifying the schema will also do the trick, e.g.: SELECT * FROM public.user

How are you accessing AGE (Command line, driver, etc.)?

  • Command line / psql

What data setup do we need to do?

  1. Run the server
    docker run --rm --name age -e POSTGRES_USER=postgresUser -e POSTGRES_PASSWORD=postgresPW -e POSTGRES_DB=postgresDB apache/age
  2. Run the client
    docker exec -ti age psql postgresql://postgresUser:ddpostgresPW@localhost/postgresDB

What is the command that caused the error?

SELECT * FROM user;
server closed the connection unexpectedly
        This probably means the server terminated abnormally
        before or while processing the request.
The connection to the server was lost. Attempting reset: Failed.
!?> 

Expected behavior
PostgreSQL using the Age extension should behave in the same way it does without it. It should perform the query on the user table.
In this case in particular, since the database is empty, it should notify that the relation user does not exist.

Environment

  • Current master (PostgreSQL 14.8 (Debian 14.8-1.pgdg120+1) on x86_64-pc-linux-gnu, compiled by gcc (Debian 12.2.0-14) 12.2.0, 64-bit)
  • Other versions are also affected (tested PG15 and PG13)

Additional context
Server logs:

The files belonging to this database system will be owned by user "postgres".
This user must also own the server process.

The database cluster will be initialized with locale "en_US.UTF-8".
The default database encoding has accordingly been set to "UTF8".
The default text search configuration will be set to "english".

Data page checksums are disabled.

fixing permissions on existing directory /var/lib/postgresql/data ... ok
creating subdirectories ... ok
selecting dynamic shared memory implementation ... posix
selecting default max_connections ... 100
selecting default shared_buffers ... 128MB
selecting default time zone ... Etc/UTC
creating configuration files ... ok
running bootstrap script ... ok
performing post-bootstrap initialization ... ok
syncing data to disk ... ok


Success. You can now start the database server using:

    pg_ctl -D /var/lib/postgresql/data -l logfile start

initdb: warning: enabling "trust" authentication for local connections
You can change this by editing pg_hba.conf or using the option -A, or
--auth-local and --auth-host, the next time you run initdb.
waiting for server to start....2023-08-08 13:29:48.911 UTC [49] LOG:  starting PostgreSQL 14.8 (Debian 14.8-1.pgdg120+1) on x86_64-pc-linux-gnu, compiled by gcc (Debian 12.2.0-14) 12.2.0, 64-bit
2023-08-08 13:29:48.914 UTC [49] LOG:  listening on Unix socket "/var/run/postgresql/.s.PGSQL.5432"
2023-08-08 13:29:48.924 UTC [50] LOG:  database system was shut down at 2023-08-08 13:29:48 UTC
2023-08-08 13:29:48.929 UTC [49] LOG:  database system is ready to accept connections
 done
server started
CREATE DATABASE


/usr/local/bin/docker-entrypoint.sh: running /docker-entrypoint-initdb.d/00-create-extension-age.sql
CREATE EXTENSION


2023-08-08 13:29:49.206 UTC [49] LOG:  received fast shutdown request
waiting for server to shut down....2023-08-08 13:29:49.210 UTC [49] LOG:  aborting any active transactions
2023-08-08 13:29:49.211 UTC [49] LOG:  background worker "logical replication launcher" (PID 56) exited with exit code 1
2023-08-08 13:29:49.212 UTC [51] LOG:  shutting down
2023-08-08 13:29:49.242 UTC [49] LOG:  database system is shut down
 done
server stopped

PostgreSQL init process complete; ready for start up.

2023-08-08 13:29:49.327 UTC [1] LOG:  starting PostgreSQL 14.8 (Debian 14.8-1.pgdg120+1) on x86_64-pc-linux-gnu, compiled by gcc (Debian 12.2.0-14) 12.2.0, 64-bit
2023-08-08 13:29:49.327 UTC [1] LOG:  listening on IPv4 address "0.0.0.0", port 5432
2023-08-08 13:29:49.327 UTC [1] LOG:  listening on IPv6 address "::", port 5432
2023-08-08 13:29:49.333 UTC [1] LOG:  listening on Unix socket "/var/run/postgresql/.s.PGSQL.5432"
2023-08-08 13:29:49.340 UTC [66] LOG:  database system was shut down at 2023-08-08 13:29:49 UTC
2023-08-08 13:29:49.348 UTC [1] LOG:  database system is ready to accept connections
2023-08-08 13:30:09.597 UTC [1] LOG:  server process (PID 85) was terminated by signal 11: Segmentation fault
2023-08-08 13:30:09.597 UTC [1] DETAIL:  Failed process was running: select * from user;
2023-08-08 13:30:09.597 UTC [1] LOG:  terminating any other active server processes
2023-08-08 13:30:09.597 UTC [86] FATAL:  the database system is in recovery mode
2023-08-08 13:30:09.598 UTC [1] LOG:  all server processes terminated; reinitializing
2023-08-08 13:30:09.613 UTC [87] LOG:  database system was interrupted; last known up at 2023-08-08 13:29:49 UTC
2023-08-08 13:30:09.695 UTC [87] LOG:  database system was not properly shut down; automatic recovery in progress
2023-08-08 13:30:09.698 UTC [87] LOG:  redo starts at 0/1867940
2023-08-08 13:30:09.698 UTC [87] LOG:  invalid record length at 0/1867978: wanted 24, got 0
2023-08-08 13:30:09.698 UTC [87] LOG:  redo done at 0/1867940 system usage: CPU: user: 0.00 s, system: 0.00 s, elapsed: 0.00 s
2023-08-08 13:30:09.717 UTC [1] LOG:  database system is ready to accept connections
@yurifari yurifari added the bug Something isn't working label Aug 8, 2023
@jrgemignani
Copy link
Contributor

@yurifari Verified -

psql-15.3-5432-pgsql=# select * from user;
    user
------------
 jgemignani
(1 row)

psql-15.3-5432-pgsql=# drop extension age cascade; create extension age; load 'age'; set search_path TO ag_catalog;
ERROR:  extension "age" does not exist
CREATE EXTENSION
LOAD
SET
psql-15.3-5432-pgsql=# select * from user;
server closed the connection unexpectedly
        This probably means the server terminated abnormally
        before or while processing the request.
The connection to the server was lost. Attempting reset: Failed.
The connection to the server was lost. Attempting reset: Failed.
!?> 

@jrgemignani
Copy link
Contributor

@yurifari I will look into this.

@jrgemignani
Copy link
Contributor

This is an interesting bug that likely goes way, way back and was just never seen. I will have a hotfix shortly.

@yurifari
Copy link
Author

yurifari commented Aug 8, 2023

Thanks @jrgemignani, much appreciated!

@jrgemignani
Copy link
Contributor

PR #1125 should fix this once reviewed and merged into the master.

@jrgemignani
Copy link
Contributor

I will be creating PRs to apply to earlier versions to fix this.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants