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

ERROR 'version-already-applied' in logs even when I start with a new database #80

Closed
AnthonyMastrean opened this issue Apr 11, 2018 · 13 comments
Assignees

Comments

@AnthonyMastrean
Copy link

AnthonyMastrean commented Apr 11, 2018

I have an ASP.NET Core application with HangFire + PostgresSQL.

services.AddHangfire(options => options.UseStorage(new PostgreSqlStorage(configuration.GetConnectionString("DefaultConnection"))));

The application and database are running in separate Docker containers, coordinated with a simple Docker Compose manifest.

version: '2.3'
services:
  scheduler:
    image: scheduler
    depends_on:
      - db
  db:
    image: postgres:9.6-alpine

Even if I start the system from scratch, I see all of these "install" ERRORs.

db_1                | PostgreSQL init process complete; ready for start up.
db_1                |
db_1                | LOG:  database system was shut down at 2018-04-11 15:03:16 UTC
db_1                | LOG:  MultiXact member wraparound protections are now enabled
db_1                | LOG:  database system is ready to accept connections
db_1                | LOG:  autovacuum launcher started
db_1                | LOG:  received smart shutdown request
db_1                | LOG:  autovacuum launcher shutting down
db_1                | LOG:  shutting down
db_1                | LOG:  database system is shut down
db_1                | LOG:  database system was shut down at 2018-04-11 15:05:59 UTC
db_1                | LOG:  MultiXact member wraparound protections are now enabled
db_1                | LOG:  database system is ready to accept connections
db_1                | LOG:  autovacuum launcher started
db_1                | ERROR:  version-already-applied
db_1                | CONTEXT:  PL/pgSQL function inline_code_block line 4 at RAISE
db_1                | STATEMENT:  --
db_1                |   -- Table structure for table `Schema`
db_1                |   --
db_1                |
db_1                |   DO
db_1                |   $$
db_1                |   BEGIN
db_1                |       IF EXISTS (SELECT 1 FROM "schema" WHERE "version"::integer >= 7) THEN
db_1                |           RAISE EXCEPTION 'version-already-applied';
db_1                |       END IF;
db_1                |   END
db_1                |   $$
db_1                | ERROR:  version-already-applied
db_1                | CONTEXT:  PL/pgSQL function inline_code_block line 4 at RAISE
db_1                | STATEMENT:  DO
db_1                |   $$
db_1                |   BEGIN
db_1                |       IF EXISTS (SELECT 1 FROM "schema" WHERE "version"::integer >= 3) THEN
db_1                |           RAISE EXCEPTION 'version-already-applied';
db_1                |       END IF;
db_1                |   END
db_1                |   $$
db_1                | ERROR:  version-already-applied
db_1                | CONTEXT:  PL/pgSQL function inline_code_block line 4 at RAISE
db_1                | STATEMENT:  --
db_1                |   -- Table structure for table `Schema`
db_1                |   --
db_1                |
db_1                |   DO
db_1                |   $$
db_1                |   BEGIN
db_1                |       IF EXISTS (SELECT 1 FROM "schema" WHERE "version"::integer >= 4) THEN
db_1                |           RAISE EXCEPTION 'version-already-applied';
db_1                |       END IF;
db_1                |   END
db_1                |   $$
db_1                | ERROR:  version-already-applied
db_1                | CONTEXT:  PL/pgSQL function inline_code_block line 4 at RAISE
db_1                | STATEMENT:  --
db_1                |   -- Table structure for table `Schema`
db_1                |   --
db_1                |
db_1                |   DO
db_1                |   $$
db_1                |   BEGIN
db_1                |       IF EXISTS (SELECT 1 FROM "schema" WHERE "version"::integer >= 5) THEN
db_1                |           RAISE EXCEPTION 'version-already-applied';
db_1                |       END IF;
db_1                |   END
db_1                |   $$
db_1                | ERROR:  version-already-applied
db_1                | CONTEXT:  PL/pgSQL function inline_code_block line 4 at RAISE
db_1                | STATEMENT:  --
db_1                |   -- Adds indices, greatly speeds-up deleting old jobs.
db_1                |   --
db_1                |
db_1                |   DO
db_1                |   $$
db_1                |   BEGIN
db_1                |       IF EXISTS (SELECT 1 FROM "schema" WHERE "version"::integer >= 6) THEN
db_1                |           RAISE EXCEPTION 'version-already-applied';
db_1                |       END IF;
db_1                |   END
db_1                |   $$
db_1                | ERROR:  version-already-applied
db_1                | CONTEXT:  PL/pgSQL function inline_code_block line 4 at RAISE
db_1                | STATEMENT:  --
db_1                |   -- Table structure for table `Schema`
db_1                |   --
db_1                |
db_1                |   DO
db_1                |   $$
db_1                |   BEGIN
db_1                |       IF EXISTS (SELECT 1 FROM "schema" WHERE "version"::integer >= 7) THEN
db_1                |           RAISE EXCEPTION 'version-already-applied';
db_1                |       END IF;
db_1                |   END
db_1                |   $$
db_1                | ERROR:  version-already-applied
db_1                | CONTEXT:  PL/pgSQL function inline_code_block line 4 at RAISE
db_1                | STATEMENT:  --
db_1                |   -- Table structure for table `Schema`
db_1                |   --
db_1                |
db_1                |   DO
db_1                |   $$
db_1                |   BEGIN
db_1                |       IF EXISTS (SELECT 1 FROM "schema" WHERE "version"::integer >= 7) THEN
db_1                |           RAISE EXCEPTION 'version-already-applied';
db_1                |       END IF;
db_1                |   END
db_1                |   $$

I definitely don't want to see ERRORs in my runtime log if nothing is actually wrong.

@vytautask vytautask self-assigned this Apr 11, 2018
@vytautask
Copy link
Collaborator

I'm confused. I've just tried it and it works perfectly within docker. No issues at all.
I have even uploaded a test project here. docker_test.zip
Could you check if you have any differences?

@AnthonyMastrean
Copy link
Author

Sorry for the delay! I wasn't able to build the example you provided (dotnet build wasn't happy about the folder/file layout). I have a minimal reproduction here: hangfire-postgres-test.zip

Oh, this is interesting... depending on the state of my system (image/layer caches? db state?), I get different results! Sometimes it shows nothing:

PS> docker-compose logs db
Attaching to hangfire-postgres-test_db_1
db_1   | The files belonging to this database system will be owned by user "postgres".
db_1   | This user must also own the server process.
db_1   |
db_1   | The database cluster will be initialized with locale "en_US.utf8".
db_1   | The default database encoding has accordingly been set to "UTF8".
db_1   | The default text search configuration will be set to "english".
db_1   |
db_1   | Data page checksums are disabled.
db_1   |
db_1   | fixing permissions on existing directory /var/lib/postgresql/data ... ok
db_1   | creating subdirectories ... ok
db_1   | selecting default max_connections ... 100
db_1   | selecting default shared_buffers ... 128MB
db_1   | selecting dynamic shared memory implementation ... posix
db_1   | creating configuration files ... ok
db_1   | running bootstrap script ... ok
db_1   | sh: locale: not found
db_1   | 2018-05-04 15:38:44.330 UTC [27] WARNING:  no usable system locales were found
db_1   | performing post-bootstrap initialization ... ok
db_1   | syncing data to disk ... ok
db_1   |
db_1   | WARNING: enabling "trust" authentication for local connections
db_1   | You can change this by editing pg_hba.conf or using the option -A, or
db_1   | --auth-local and --auth-host, the next time you run initdb.
db_1   |
db_1   | Success. You can now start the database server using:
db_1   |
db_1   |     pg_ctl -D /var/lib/postgresql/data -l logfile start
db_1   |
db_1   | waiting for server to start....2018-05-04 15:38:45.565 UTC [32] LOG:  listening on IPv4 address "127.0.0.1", port 5432
db_1   | 2018-05-04 15:38:45.565 UTC [32] LOG:  could not bind IPv6 address "::1": Address not available
db_1   | 2018-05-04 15:38:45.565 UTC [32] HINT:  Is another postmaster already running on port 5432? If not, wait a few seconds and retry.
db_1   | 2018-05-04 15:38:45.584 UTC [32] LOG:  listening on Unix socket "/var/run/postgresql/.s.PGSQL.5432"
db_1   | 2018-05-04 15:38:45.627 UTC [33] LOG:  database system was shut down at 2018-05-04 15:38:44 UTC
db_1   | 2018-05-04 15:38:45.632 UTC [32] LOG:  database system is ready to accept connections
db_1   |  done
db_1   | server started
db_1   | CREATE DATABASE
db_1   |
db_1   | CREATE ROLE
db_1   |
db_1   |
db_1   | /usr/local/bin/docker-entrypoint.sh: ignoring /docker-entrypoint-initdb.d/*
db_1   |
db_1   | 2018-05-04 15:38:46.029 UTC [32] LOG:  received fast shutdown request
db_1   | waiting for server to shut down....2018-05-04 15:38:46.033 UTC [32] LOG:  aborting any active transactions
db_1   | 2018-05-04 15:38:46.035 UTC [32] LOG:  worker process: logical replication launcher (PID 39) exited with exit code 1
db_1   | 2018-05-04 15:38:46.035 UTC [34] LOG:  shutting down
db_1   | 2018-05-04 15:38:46.085 UTC [32] LOG:  database system is shut down
db_1   |  done
db_1   | server stopped
db_1   |
db_1   | PostgreSQL init process complete; ready for start up.
db_1   |
db_1   | 2018-05-04 15:38:46.141 UTC [1] LOG:  listening on IPv4 address "0.0.0.0", port 5432
db_1   | 2018-05-04 15:38:46.141 UTC [1] LOG:  listening on IPv6 address "::", port 5432
db_1   | 2018-05-04 15:38:46.162 UTC [1] LOG:  listening on Unix socket "/var/run/postgresql/.s.PGSQL.5432"
db_1   | 2018-05-04 15:38:46.198 UTC [45] LOG:  database system was shut down at 2018-05-04 15:38:46 UTC
db_1   | 2018-05-04 15:38:46.206 UTC [1] LOG:  database system is ready to accept connections

Sometimes it shows just the latest version warning:

PS> docker-compose up --build -d
...
PS> docker-compose logs db
Attaching to hangfire-postgres-test_db_1
db_1   | The files belonging to this database system will be owned by user "postgres".
db_1   | This user must also own the server process.
db_1   |
db_1   | The database cluster will be initialized with locale "en_US.utf8".
db_1   | The default database encoding has accordingly been set to "UTF8".
db_1   | The default text search configuration will be set to "english".
db_1   |
db_1   | Data page checksums are disabled.
db_1   |
db_1   | fixing permissions on existing directory /var/lib/postgresql/data ... ok
db_1   | creating subdirectories ... ok
db_1   | selecting default max_connections ... 100
db_1   | selecting default shared_buffers ... 128MB
db_1   | selecting dynamic shared memory implementation ... posix
db_1   | creating configuration files ... ok
db_1   | running bootstrap script ... ok
db_1   | sh: locale: not found
db_1   | 2018-05-04 15:38:44.330 UTC [27] WARNING:  no usable system locales were found
db_1   | performing post-bootstrap initialization ... ok
db_1   | syncing data to disk ... ok
db_1   |
db_1   | WARNING: enabling "trust" authentication for local connections
db_1   | You can change this by editing pg_hba.conf or using the option -A, or
db_1   | --auth-local and --auth-host, the next time you run initdb.
db_1   |
db_1   | Success. You can now start the database server using:
db_1   |
db_1   |     pg_ctl -D /var/lib/postgresql/data -l logfile start
db_1   |
db_1   | waiting for server to start....2018-05-04 15:38:45.565 UTC [32] LOG:  listening on IPv4 address "127.0.0.1", port 5432
db_1   | 2018-05-04 15:38:45.565 UTC [32] LOG:  could not bind IPv6 address "::1": Address not available
db_1   | 2018-05-04 15:38:45.565 UTC [32] HINT:  Is another postmaster already running on port 5432? If not, wait a few seconds and retry.
db_1   | 2018-05-04 15:38:45.584 UTC [32] LOG:  listening on Unix socket "/var/run/postgresql/.s.PGSQL.5432"
db_1   | 2018-05-04 15:38:45.627 UTC [33] LOG:  database system was shut down at 2018-05-04 15:38:44 UTC
db_1   | 2018-05-04 15:38:45.632 UTC [32] LOG:  database system is ready to accept connections
db_1   |  done
db_1   | server started
db_1   | CREATE DATABASE
db_1   |
db_1   | CREATE ROLE
db_1   |
db_1   |
db_1   | /usr/local/bin/docker-entrypoint.sh: ignoring /docker-entrypoint-initdb.d/*
db_1   |
db_1   | 2018-05-04 15:38:46.029 UTC [32] LOG:  received fast shutdown request
db_1   | waiting for server to shut down....2018-05-04 15:38:46.033 UTC [32] LOG:  aborting any active transactions
db_1   | 2018-05-04 15:38:46.035 UTC [32] LOG:  worker process: logical replication launcher (PID 39) exited with exit code 1
db_1   | 2018-05-04 15:38:46.035 UTC [34] LOG:  shutting down
db_1   | 2018-05-04 15:38:46.085 UTC [32] LOG:  database system is shut down
db_1   |  done
db_1   | server stopped
db_1   |
db_1   | PostgreSQL init process complete; ready for start up.
db_1   |
db_1   | 2018-05-04 15:38:46.141 UTC [1] LOG:  listening on IPv4 address "0.0.0.0", port 5432
db_1   | 2018-05-04 15:38:46.141 UTC [1] LOG:  listening on IPv6 address "::", port 5432
db_1   | 2018-05-04 15:38:46.162 UTC [1] LOG:  listening on Unix socket "/var/run/postgresql/.s.PGSQL.5432"
db_1   | 2018-05-04 15:38:46.198 UTC [45] LOG:  database system was shut down at 2018-05-04 15:38:46 UTC
db_1   | 2018-05-04 15:38:46.206 UTC [1] LOG:  database system is ready to accept connections
db_1   | 2018-05-04 15:38:47.101 UTC [52] ERROR:  version-already-applied
db_1   | 2018-05-04 15:38:47.101 UTC [52] CONTEXT:  PL/pgSQL function inline_code_block line 4 at RAISE
db_1   | 2018-05-04 15:38:47.101 UTC [52] STATEMENT:  --
db_1   |        -- Table structure for table `Schema`
db_1   |        --
db_1   |
db_1   |        DO
db_1   |        $$
db_1   |        BEGIN
db_1   |            IF EXISTS (SELECT 1 FROM "schema" WHERE "version"::integer >= 7) THEN
db_1   |                RAISE EXCEPTION 'version-already-applied';
db_1   |            END IF;
db_1   |        END
db_1   |        $$

And sometimes I can get it to show all version warnings! Usually if I restart the service...

PS> docker-compose restart app
...
PS> docker-compose logs db
Attaching to hangfire-postgres-test_db_1
db_1   | The files belonging to this database system will be owned by user "postgres".
db_1   | This user must also own the server process.
db_1   |
db_1   | The database cluster will be initialized with locale "en_US.utf8".
db_1   | The default database encoding has accordingly been set to "UTF8".
db_1   | The default text search configuration will be set to "english".
db_1   |
db_1   | Data page checksums are disabled.
db_1   |
db_1   | fixing permissions on existing directory /var/lib/postgresql/data ... ok
db_1   | creating subdirectories ... ok
db_1   | selecting default max_connections ... 100
db_1   | selecting default shared_buffers ... 128MB
db_1   | selecting dynamic shared memory implementation ... posix
db_1   | creating configuration files ... ok
db_1   | running bootstrap script ... ok
db_1   | sh: locale: not found
db_1   | 2018-05-04 15:38:44.330 UTC [27] WARNING:  no usable system locales were found
db_1   | performing post-bootstrap initialization ... ok
db_1   | syncing data to disk ... ok
db_1   |
db_1   | WARNING: enabling "trust" authentication for local connections
db_1   | You can change this by editing pg_hba.conf or using the option -A, or
db_1   | --auth-local and --auth-host, the next time you run initdb.
db_1   |
db_1   | Success. You can now start the database server using:
db_1   |
db_1   |     pg_ctl -D /var/lib/postgresql/data -l logfile start
db_1   |
db_1   | waiting for server to start....2018-05-04 15:38:45.565 UTC [32] LOG:  listening on IPv4 address "127.0.0.1", port 5432
db_1   | 2018-05-04 15:38:45.565 UTC [32] LOG:  could not bind IPv6 address "::1": Address not available
db_1   | 2018-05-04 15:38:45.565 UTC [32] HINT:  Is another postmaster already running on port 5432? If not, wait a few seconds and retry.
db_1   | 2018-05-04 15:38:45.584 UTC [32] LOG:  listening on Unix socket "/var/run/postgresql/.s.PGSQL.5432"
db_1   | 2018-05-04 15:38:45.627 UTC [33] LOG:  database system was shut down at 2018-05-04 15:38:44 UTC
db_1   | 2018-05-04 15:38:45.632 UTC [32] LOG:  database system is ready to accept connections
db_1   |  done
db_1   | server started
db_1   | CREATE DATABASE
db_1   |
db_1   | CREATE ROLE
db_1   |
db_1   |
db_1   | /usr/local/bin/docker-entrypoint.sh: ignoring /docker-entrypoint-initdb.d/*
db_1   |
db_1   | 2018-05-04 15:38:46.029 UTC [32] LOG:  received fast shutdown request
db_1   | waiting for server to shut down....2018-05-04 15:38:46.033 UTC [32] LOG:  aborting any active transactions
db_1   | 2018-05-04 15:38:46.035 UTC [32] LOG:  worker process: logical replication launcher (PID 39) exited with exit code 1
db_1   | 2018-05-04 15:38:46.035 UTC [34] LOG:  shutting down
db_1   | 2018-05-04 15:38:46.085 UTC [32] LOG:  database system is shut down
db_1   |  done
db_1   | server stopped
db_1   |
db_1   | PostgreSQL init process complete; ready for start up.
db_1   |
db_1   | 2018-05-04 15:38:46.141 UTC [1] LOG:  listening on IPv4 address "0.0.0.0", port 5432
db_1   | 2018-05-04 15:38:46.141 UTC [1] LOG:  listening on IPv6 address "::", port 5432
db_1   | 2018-05-04 15:38:46.162 UTC [1] LOG:  listening on Unix socket "/var/run/postgresql/.s.PGSQL.5432"
db_1   | 2018-05-04 15:38:46.198 UTC [45] LOG:  database system was shut down at 2018-05-04 15:38:46 UTC
db_1   | 2018-05-04 15:38:46.206 UTC [1] LOG:  database system is ready to accept connections
db_1   | 2018-05-04 15:38:47.101 UTC [52] ERROR:  version-already-applied
db_1   | 2018-05-04 15:38:47.101 UTC [52] CONTEXT:  PL/pgSQL function inline_code_block line 4 at RAISE
db_1   | 2018-05-04 15:38:47.101 UTC [52] STATEMENT:  --
db_1   |        -- Table structure for table `Schema`
db_1   |        --
db_1   |
db_1   |        DO
db_1   |        $$
db_1   |        BEGIN
db_1   |            IF EXISTS (SELECT 1 FROM "schema" WHERE "version"::integer >= 7) THEN
db_1   |                RAISE EXCEPTION 'version-already-applied';
db_1   |            END IF;
db_1   |        END
db_1   |        $$
db_1   | 2018-05-04 15:42:06.678 UTC [68] ERROR:  version-already-applied
db_1   | 2018-05-04 15:42:06.678 UTC [68] CONTEXT:  PL/pgSQL function inline_code_block line 4 at RAISE
db_1   | 2018-05-04 15:42:06.678 UTC [68] STATEMENT:  DO
db_1   |        $$
db_1   |        BEGIN
db_1   |            IF EXISTS (SELECT 1 FROM "schema" WHERE "version"::integer >= 3) THEN
db_1   |                RAISE EXCEPTION 'version-already-applied';
db_1   |            END IF;
db_1   |        END
db_1   |        $$
db_1   | 2018-05-04 15:42:06.703 UTC [68] ERROR:  version-already-applied
db_1   | 2018-05-04 15:42:06.703 UTC [68] CONTEXT:  PL/pgSQL function inline_code_block line 4 at RAISE
db_1   | 2018-05-04 15:42:06.703 UTC [68] STATEMENT:  --
db_1   |        -- Table structure for table `Schema`
db_1   |        --
db_1   |
db_1   |        DO
db_1   |        $$
db_1   |        BEGIN
db_1   |            IF EXISTS (SELECT 1 FROM "schema" WHERE "version"::integer >= 4) THEN
db_1   |                RAISE EXCEPTION 'version-already-applied';
db_1   |            END IF;
db_1   |        END
db_1   |        $$
db_1   | 2018-05-04 15:42:06.706 UTC [68] ERROR:  version-already-applied
db_1   | 2018-05-04 15:42:06.706 UTC [68] CONTEXT:  PL/pgSQL function inline_code_block line 4 at RAISE
db_1   | 2018-05-04 15:42:06.706 UTC [68] STATEMENT:  --
db_1   |        -- Table structure for table `Schema`
db_1   |        --
db_1   |
db_1   |        DO
db_1   |        $$
db_1   |        BEGIN
db_1   |            IF EXISTS (SELECT 1 FROM "schema" WHERE "version"::integer >= 5) THEN
db_1   |                RAISE EXCEPTION 'version-already-applied';
db_1   |            END IF;
db_1   |        END
db_1   |        $$
db_1   | 2018-05-04 15:42:06.708 UTC [68] ERROR:  version-already-applied
db_1   | 2018-05-04 15:42:06.708 UTC [68] CONTEXT:  PL/pgSQL function inline_code_block line 4 at RAISE
db_1   | 2018-05-04 15:42:06.708 UTC [68] STATEMENT:  --
db_1   |        -- Adds indices, greatly speeds-up deleting old jobs.
db_1   |        --
db_1   |
db_1   |        DO
db_1   |        $$
db_1   |        BEGIN
db_1   |            IF EXISTS (SELECT 1 FROM "schema" WHERE "version"::integer >= 6) THEN
db_1   |                RAISE EXCEPTION 'version-already-applied';
db_1   |            END IF;
db_1   |        END
db_1   |        $$
db_1   | 2018-05-04 15:42:06.712 UTC [68] ERROR:  version-already-applied
db_1   | 2018-05-04 15:42:06.712 UTC [68] CONTEXT:  PL/pgSQL function inline_code_block line 4 at RAISE
db_1   | 2018-05-04 15:42:06.712 UTC [68] STATEMENT:  --
db_1   |        -- Table structure for table `Schema`
db_1   |        --
db_1   |
db_1   |        DO
db_1   |        $$
db_1   |        BEGIN
db_1   |            IF EXISTS (SELECT 1 FROM "schema" WHERE "version"::integer >= 7) THEN
db_1   |                RAISE EXCEPTION 'version-already-applied';
db_1   |            END IF;
db_1   |        END
db_1   |        $$
db_1   | 2018-05-04 15:42:06.716 UTC [68] ERROR:  version-already-applied
db_1   | 2018-05-04 15:42:06.716 UTC [68] CONTEXT:  PL/pgSQL function inline_code_block line 4 at RAISE
db_1   | 2018-05-04 15:42:06.716 UTC [68] STATEMENT:  --
db_1   |        -- Table structure for table `Schema`
db_1   |        --
db_1   |
db_1   |        DO
db_1   |        $$
db_1   |        BEGIN
db_1   |            IF EXISTS (SELECT 1 FROM "schema" WHERE "version"::integer >= 7) THEN
db_1   |                RAISE EXCEPTION 'version-already-applied';
db_1   |            END IF;
db_1   |        END
db_1   |        $$

@AnthonyMastrean
Copy link
Author

AnthonyMastrean commented May 4, 2018

I understand now why the schema code is running multiple times (app restarts, for example). I wonder if it's necessary to use RAISE EXCEPTION. It's triggering my "spider sense" when browsing through the logs 😄

@AnthonyMastrean
Copy link
Author

Is it really necessary to RAISE EXCEPTION in this case? Would it be more appropriate to RAISE NOTICE?

https://www.postgresql.org/docs/current/static/plpgsql-errors-and-messages.html

@vytautask
Copy link
Collaborator

IMHO, yes. In that documentation link you provided there is a sentence:

EXCEPTION raises an error (which normally aborts the current transaction); the other levels only generate messages of different priority levels.

@frankhommers
Copy link
Collaborator

It is an exception so that it aborts the rest of the script.

And also the exception gets handled here: https://github.com/frankhommers/Hangfire.PostgreSql/blob/0085a3fe1fb9b02ebf4c245f7b1a0b7521ae74a5/src/Hangfire.PostgreSql/PostgreSqlObjectsInstaller.cs#L91

It would take a lot more changes than the ones in your pull request to fix this.

@mbrookson
Copy link

mbrookson commented May 4, 2019

I'm seeing this same version-already-applied error when running on macOS with a debugger.

When just running without the debugger, it all seems to run fine and after inspection the schema tables contains the version value 10.

However, when running with the debugger, it manages to create the hangfire schema but throws an exception. After inspection the schema tables contains only the version value 7 so it seems to be breaking somewhere after logging "Start installing Hangfire SQL objects..." to the console.

I appreciate this isn't lots of information but any ideas as to the what the problem is? Using Hangfire.Core 1.6.25, Hangfire.AspNetCore 1.6.25 and Hangfire.PostgreSql 1.6.0 (but was also happening with Hangfire.PostgreSql 1.5.0)

@mterwoord
Copy link

The exceptions are handled, so the debugger might trigger, but you can just continue.

@mbrookson
Copy link

Ah yes, you're right! Turning off JetBrains Rider's "Break on user-unhandled exception" setting fixed my issue 👍

@frankhommers
Copy link
Collaborator

What should we do now? Since throwing exceptions were part of the design.

@AnthonyMastrean
Copy link
Author

I'm still of the mind that "version already applied" is a normal situation and should not pollute my service logs with exceptions. If I get some time, I can try to address the deeper workflow problem (this is why they say "don't use exceptions for control flow")

@frankhommers
Copy link
Collaborator

You are free to rewrite the scripts so that they exit early and do not continue when the version is already applied without exceptions. A PR for this is welcome. Just changing RAISE EXCEPTION to RAISE NOTICE is not enough as the script continues after RAISE NOTICE.

Inspiration can be found here: https://github.com/HangfireIO/Hangfire/blob/master/src/Hangfire.SqlServer/Install.sql

@frankhommers
Copy link
Collaborator

I fixed it myself. Will be in the next release.

frankhommers added a commit that referenced this issue May 6, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants