Skip to content

Redshift connection fails with: database "postgres" does not exist #511

Closed

Description

@andrewwwooster

I am trying to use Npgsql.EntityFramework with the Amazon Redshift database.
Following comments in issue #163 I downloaded a match to lc_monetary fix from here:
https://build.npgsql.org/viewLog.html?buildId=14051&tab=artifacts&buildTypeId=npgsql_All22
I no longer get the lc_monetary error, but I do get the following exception:
Npgsql.NpgsqlException: FATAL: 3D000: database "postgres" does not exist

Redshift does not have a database named "postgres", why is Npgsql.EntityFramework looking for this database?

System.Data.Entity.Core.ProviderIncompatibleException: An error occurred accessing the database. This usually means that the connection to the database failed. Check that the connection string is correct and that the appropriate DbContext constructor is being used to specify it or find it in the application's config file. See http://go.microsoft.com/fwlink/?LinkId=386386 for information on DbContext and connections. See the inner exception for details of the failure. ---> System.Data.Entity.Core.ProviderIncompatibleException: The provider did not return a ProviderManifestToken string. ---> Npgsql.NpgsqlException: FATAL: 3D000: database "postgres" does not exist
Result StackTrace:
at Npgsql.NpgsqlState.d__0.MoveNext() in c:\dev\TeamCity\buildAgent\work\45caad201a245970\Npgsql\Npgsql\NpgsqlState.BackendResponse.cs:line 143
at Npgsql.NpgsqlState.ProcessAndDiscardBackendResponses(NpgsqlConnector context) in c:\dev\TeamCity\buildAgent\work\45caad201a245970\Npgsql\Npgsql\NpgsqlState.cs:line 283
at Npgsql.NpgsqlConnectedState.Startup(NpgsqlConnector context, NpgsqlConnectionStringBuilder settings) in c:\dev\TeamCity\buildAgent\work\45caad201a245970\Npgsql\Npgsql\NpgsqlConnectedState.cs:line 47
at Npgsql.NpgsqlConnector.Open() in c:\dev\TeamCity\buildAgent\work\45caad201a245970\Npgsql\Npgsql\NpgsqlConnector.cs:line 801
at Npgsql.NpgsqlConnectorPool.GetPooledConnector(NpgsqlConnection Connection) in c:\dev\TeamCity\buildAgent\work\45caad201a245970\Npgsql\Npgsql\NpgsqlConnectorPool.cs:line 393
at Npgsql.NpgsqlConnectorPool.RequestPooledConnectorInternal(NpgsqlConnection Connection) in c:\dev\TeamCity\buildAgent\work\45caad201a245970\Npgsql\Npgsql\NpgsqlConnectorPool.cs:line 236
at Npgsql.NpgsqlConnectorPool.RequestConnector(NpgsqlConnection Connection) in c:\dev\TeamCity\buildAgent\work\45caad201a245970\Npgsql\Npgsql\NpgsqlConnectorPool.cs:line 180
at Npgsql.NpgsqlConnection.Open() in c:\dev\TeamCity\buildAgent\work\45caad201a245970\Npgsql\Npgsql\NpgsqlConnection.cs:line 639
at Npgsql.NpgsqlServices.UsingPostgresDBConnection(NpgsqlConnection connection, Action1 action) in c:\dev\TeamCity\buildAgent\work\45caad201a245970\Npgsql.EntityFramework\NpgsqlServices.cs:line 164 at Npgsql.NpgsqlServices.GetDbProviderManifestToken(DbConnection connection) in c:\dev\TeamCity\buildAgent\work\45caad201a245970\Npgsql.EntityFramework\NpgsqlServices.cs:line 102 at System.Data.Entity.Core.Common.DbProviderServices.GetProviderManifestToken(DbConnection connection) --- End of inner exception stack trace --- at System.Data.Entity.Core.Common.DbProviderServices.GetProviderManifestToken(DbConnection connection) at System.Data.Entity.Utilities.DbProviderServicesExtensions.GetProviderManifestTokenChecked(DbProviderServices providerServices, DbConnection connection) --- End of inner exception stack trace --- at System.Data.Entity.Utilities.DbProviderServicesExtensions.GetProviderManifestTokenChecked(DbProviderServices providerServices, DbConnection connection) at System.Data.Entity.Infrastructure.DefaultManifestTokenResolver.<>c__DisplayClass1.<ResolveManifestToken>b__0(Tuple3 k)
at System.Collections.Concurrent.ConcurrentDictionary2.GetOrAdd(TKey key, Func2 valueFactory)
at System.Data.Entity.Infrastructure.DefaultManifestTokenResolver.ResolveManifestToken(DbConnection connection)
at System.Data.Entity.Utilities.DbConnectionExtensions.GetProviderInfo(DbConnection connection, DbProviderManifest& providerManifest)
at System.Data.Entity.DbModelBuilder.Build(DbConnection providerConnection)
at System.Data.Entity.Internal.LazyInternalContext.CreateModel(LazyInternalContext internalContext)
at System.Data.Entity.Internal.RetryLazy2.GetValue(TInput input) at System.Data.Entity.Internal.LazyInternalContext.InitializeContext() at System.Data.Entity.Internal.InternalContext.GetEntitySetAndBaseTypeForType(Type entityType) at System.Data.Entity.Internal.Linq.InternalSet1.Initialize()
at System.Data.Entity.Internal.Linq.InternalSet1.get_InternalContext() at System.Data.Entity.Infrastructure.DbQuery1.System.Linq.IQueryable.get_Provider()
at System.Linq.Queryable.Where[TSource](IQueryable1 source, Expression1 predicate)
at Minerva.Tests.Models.DiagnosisDbContextTest.DrugCodes_ByProductName_ReturnsMany() in c:\Users\Andrew\Source\Repos\Minerva\Minerva.Tests\Models\Entities\DiagnosisDbContextTest.cs:line 56

Activity

  1. Emill commented on Mar 2, 2015

    @Emill
    Contributor

    Hi. I think this is the same as #278. Maybe @DavidKarlas has found some workaround?

  2. franciscojunior commented on Mar 2, 2015

    @franciscojunior
    Member

    Hi, @andrewwwooster !

    Can you check if you have a database called template1 in your Amazon redshift server? "postgres" is the name of the database npgsql is trying to connect. This value is hardcoded because this database was supposed to exist in every postgresql server. It seems Redshift isn't the case.

    @DavidKarlas , although you say here (#278 (comment)) that UsingPostgresDbConnection method would only be used when creating and deleting database, I think there is another case where it is used: GetDbProviderManifestToken. Isn't the database created yet and that's why the code is trying to connect to the "master" database?
    I think that if we can get the confirmation that template1 database exists in redshift, I think we can change "postgres" to "template1". What do you think?

  3. roji commented on Mar 2, 2015

    @roji
    Member

    Good thing I just noticed this, I was about to release 2.2.5 but it would be good to solve this for that version.

    It's really annoying not to have a Redshift instance to test on. @franciscojunior, your idea sounds good: according to the PostgreSQL Template Databases page the template1 database exists all the way back to 7.3. It also seems that the pgadmin GUI also connects to template1.

    Any other ideas or objections?

  4. added this to the 2.2.5 milestone on Mar 2, 2015
  5. DavidKarlas commented on Mar 2, 2015

    @DavidKarlas
    Contributor

    If @andrewwwooster confirms "template1" exist on RedShift, making this change makes sense...

    Assumptions are root of most bugs :D, I just assumed "postgres" is always there...

    Btw maybe this can be used to detect if database is "RedShift" or "real Postgres" at runtime.

  6. roji commented on Mar 2, 2015

    @roji
    Member

    @DavidKarlas, it appears that this isn't a Redshift-specific issue, the postgresql database is there starting from PG 8.1 according to the docs.

    AFAIK there isn't any truly Redshift-specific weirdness that Npgsql needs to care about, the only issues I'm aware of (like this one) are a result of the old PG version they forked from (8.0).

    But that may change :)

    @andrewwwooster, we'll wait for your confirmation.

  7. roji commented on Mar 2, 2015

    @roji
    Member

    OK, @Emill set up a test Redshift instance for us (thanks!), and I can confirm that it has the "template1" database.

    I'll implement @franciscojunior suggestion and switch the "maintenance" database to template1, and then probably release 2.2.5

  8. added a commit that references this issue on Mar 2, 2015
    7e26f33
  9. andrewwwooster commented on Mar 3, 2015

    @andrewwwooster
    Author

    I totally agree that this project needs a Redshift test environment. And it would make a lot of sense for Amazon to make one available.

    Thanks @emil for getting one setup.

    It is possible to get a two month free trial environment here:
    http://aws.amazon.com/redshift/free-trial/

  10. roji commented on Mar 3, 2015

    @roji
    Member

    I actually contacted AWS and even got to a call with a sales representative, but nothing's come out of it. If anyone has any idea of who to contact for AWS open source let me know...

    @Emill's test instance will work for now but it would be much better to have a permanent instance with a build agent running our test suite in continuous integration...

  11. Emill commented on Mar 15, 2015

    @Emill
    Contributor

    As described here, http://stackoverflow.com/questions/28067056/unable-to-connect-to-heroku-postgres-from-a-net-application-npgsql, heroku does not provide access to the "postgres" db and neither to "template1". For the case for getting the server version (GetDbProviderManifestToken), there is no need to connect to another database than the one the user specified, so we could fix that quite easily.

  12. roji commented on Mar 16, 2015

    @roji
    Member

    Sounds good @Emill, opened #534 for 2.2.6

  13. DavidKarlas commented on Mar 16, 2015

    @DavidKarlas
    Contributor

    If it doesn't provide any database... How can we connect to it to create new database in EF?

  14. Emill commented on Mar 16, 2015

    @Emill
    Contributor

    At least their free version is shared hosting with hundreds of dbs on the same server. You have to create a db through their website (or maybe through one of their tools).

  15. added theissue type on Jun 18, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Labels

Type

Projects

No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions