2

I'm running an old postgresql database that was originally installed as v9.6 and I'm progressively upgrading it from one version to the next until I can get it up to date with version 13.3. The upgrades from 9.6 to 10, and 10 to 11 were successful. However when I try to upgrade to version 12 I get the following error:

bash-4.4$ tail pg_upgrade_dump_16421.log
pg_restore: creating TYPE "public.gtrgm"
pg_restore: creating FUNCTION "public.Seqnextval("abstime")"
pg_restore: while PROCESSING TOC:
pg_restore: from TOC entry 662; 1255 16425 FUNCTION Seqnextval("abstime") effective
pg_restore: error: could not execute query: ERROR:  type abstime does not exist
Command was: CREATE FUNCTION "public"."Seqnextval"("abstime") RETURNS bigint
    LANGUAGE "sql"
    AS $$select setval('units_id_seq', (select max(id) from units)+1) from units limit 1;$$;

Here are the steps that I've taken from 11 to 12 to get to where I am right now:

B) Upgrade to PostgreSQL 12

  1. Update packages and install postgres

    sudo yum update
    sudo yum install postgresql12
    
  2. Stop the postgresql services

    sudo systemctl stop postgresql-11.service
    sudo systemctl stop postgresql-12.service
    
  3. Log in as the postgres user again

    sudo su postgres
    
  4. Change to the home directory

    cd ~
    
  5. Migrate the data

    /usr/pgsql-12/bin/pg_upgrade --old-datadir=/var/lib/pgsql/11/data --new-datadir=/var/lib/pgsql/12/data --old-bindir=/usr/pgsql-11/bin --new-bindir=/usr/pgsql-12/bin --old-options '-c config_file=/var/lib/pgsql/11/data/postgresql.conf' --new-options '-c config_file=/var/lib/pgsql/12/data/postgresql.conf'
    
  6. Switch to regular user

     exit
    
  7. Swap the ports the old and new postgres versions.

     sudo nano /var/lib/pgsql/12/data/postgresql.conf
     _change port to 5432_
     sudo nano /var/lib/pgsql/11/data/postgresql.conf
     _change port to 5433_
    
  8. Start the postgresql service

     sudo systemctl start postgresql-12.service
    
  9. Log in as postgres user

    sudo su postgres
    cd ~
    
  10. Check your new postgres version

    psql -c "SELECT version();"
    
  11. Run the generated new cluster script

     ./analyze_new_cluster.sh
    
  12. Return as a normal (default user) user and cleanup up the old version's mess

    exit
    sudo yum remove postgresql11
    sudo rm -rf /etc/postgresql/11/
    sudo su postgres
    cd ~
    ./delete_old_cluster.sh
    

I know for sure that the abstime datatype has been removed in postgresql 12. Does anyone here know how to resolve this issue so I can continue with my upgrades? Please let me know, thanks! Also if you have any questions, I'm all ears.

Adam Steinberger
  • 545
  • 1
  • 5
  • 16
  • The only way I can think of is in the Postgres 11 instance find and change the `abstime` occurrences to something else. To do so it might be useful to do a `pg_dump -s` to get only the schema definitions and search that for `abstime`. – Adrian Klaver Jul 30 '21 at 19:31
  • 1
    Seems you have a user-defined function called `"public"."Seqnextval"` (as per the error output `Command was: CREATE FUNCTION "public"."Seqnextval"("abstime")...`. I think the best option is to drop the function before using `pg_upgrade`. After upgrade, you can re-write/re-define the function to work with v. 12 – richyen Jul 30 '21 at 20:38
  • From what I see in error message: `abstime` argument is not used inside function. You can substitute it with even `anyelement`. But it's possible that there are other functions exists that use `abstime` – Alex Yu Jul 31 '21 at 06:07

1 Answers1

1

What's possible to do with function "Seqnextval"

CREATE FUNCTION "public"."Seqnextval"("abstime") 
RETURNS bigint
LANGUAGE "sql"
AS $$
select setval('units_id_seq', (select max(id) from units)+1) from units limit 1;
$$;

Note that argument of type abstime is never used in function.

I suppose it must be safe to change it to:

CREATE FUNCTION "public"."Seqnextval"(anyelement)

then rerun upgrade process.

What must be possible to do with abstime in general

It could be possible there are other functions that use abstime.

Look for other functions:

WITH funcs AS (
SELECT 
        P.proname,
        p.pronamespace::regnamespace::text AS func_schema,
        obj_description(p.oid),
        pg_catalog.pg_get_function_arguments(p.oid) AS args,                
        pg_get_function_result(p.oid) AS rettype
    FROM 
        pg_proc P
)
SELECT 
        * 
    FROM 
        funcs
    WHERE
        (args ~~ '%abstime%'
            OR rettype = 'abstime'
        )
        AND func_schema <> 'pg_catalog' 

Other tables/views:

SELECT * FROM information_schema."columns" 
WHERE
    data_type = 'abstime'
    AND table_schema <> 'pg_catalog'

If there are no other functions and relations - you're lucky.

Otherwise:

  • inspect each function/relation
  • decide how to modify them or delegate it to someone other
  • change them
  • restart upgrade process
Alex Yu
  • 3,412
  • 1
  • 25
  • 38
  • So I ran `DROP FUNCTION "public"."Seqnextval"("abstime")` in `postgres` 11 and that worked, however when I reran the `postgres` 12 upgrade it runs into the same exact problem. Any idea how to prevent this problem from reoccurring? – Adam Steinberger Aug 02 '21 at 13:28
  • 1
    Turns out I was dropping as the wrong user, problem solved! – Adam Steinberger Aug 02 '21 at 15:01