Я пишу EF-приложение на основе https://docs.microsoft.com/en-us/ef/core/get-started/?tabs=netcore-cli#create -the-database , за исключением того, что я использую postgresql.
Мой класс DbContext имеет
protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
{
optionsBuilder.UseNpgsql(
@"Server=localhost;Port=5432;Database=Blogging;User Id=postgres;Password=abc;");
}
, и мне не удается его запустить:
$ dotnet run
Inserting a new blog
Unhandled exception. Npgsql.PostgresException (0x80004005): 28P01: password authentication failed for user "postgres"
at Npgsql.NpgsqlConnector.<>c__DisplayClass160_0.<<DoReadMessage>g__ReadMessageLong|0>d.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
at Npgsql.NpgsqlConnector.<>c__DisplayClass160_0.<<DoReadMessage>g__ReadMessageLong|0>d.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
at Npgsql.NpgsqlConnector.AuthenticateMD5(String username, Byte[] salt, Boolean async)
at Npgsql.NpgsqlConnector.Authenticate(String username, NpgsqlTimeout timeout, Boolean async)
at Npgsql.NpgsqlConnector.Open(NpgsqlTimeout timeout, Boolean async, CancellationToken cancellationToken)
at Npgsql.ConnectorPool.AllocateLong(NpgsqlConnection conn, NpgsqlTimeout timeout, Boolean async, CancellationToken cancellationToken)
at Npgsql.NpgsqlConnection.<>c__DisplayClass32_0.<<Open>g__OpenLong|0>d.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
at Npgsql.NpgsqlConnection.Open()
at Microsoft.EntityFrameworkCore.Storage.RelationalConnection.OpenDbConnection(Boolean errorsExpected)
at Microsoft.EntityFrameworkCore.Storage.RelationalConnection.Open(Boolean errorsExpected)
at Microsoft.EntityFrameworkCore.Storage.RelationalConnection.BeginTransaction(IsolationLevel isolationLevel)
at Microsoft.EntityFrameworkCore.Storage.RelationalConnection.BeginTransaction()
at Microsoft.EntityFrameworkCore.Update.Internal.BatchExecutor.Execute(IEnumerable`1 commandBatches, IRelationalConnection connection)
at Microsoft.EntityFrameworkCore.Storage.RelationalDatabase.SaveChanges(IList`1 entries)
at Microsoft.EntityFrameworkCore.ChangeTracking.Internal.StateManager.SaveChanges(IList`1 entriesToSave)
at Microsoft.EntityFrameworkCore.ChangeTracking.Internal.StateManager.SaveChanges(DbContext _, Boolean acceptAllChangesOnSuccess)
at Npgsql.EntityFrameworkCore.PostgreSQL.Storage.Internal.NpgsqlExecutionStrategy.Execute[TState,TResult](TState state, Func`3 operation, Func`3 verifySucceeded)
at Microsoft.EntityFrameworkCore.ChangeTracking.Internal.StateManager.SaveChanges(Boolean acceptAllChangesOnSuccess)
at Microsoft.EntityFrameworkCore.DbContext.SaveChanges(Boolean acceptAllChangesOnSuccess)
at Microsoft.EntityFrameworkCore.DbContext.SaveChanges()
at EFGetStarted.Program.Main() in /home/ethan/mydata/academic discipline/study objects/areas/formal systems/math/categories of mathematics/meta math, or foundations of math/composition/set theory/a class of sets/operations/product space/a subset ie relation/programming/database/data models/specific-data-models/convert/add-query-engine-above-query-engine/Relational2Object/CSharp/EntityFramework/official/202010/code/EFGetStarted/Program.cs:line 14
Exception data:
Severity: FATAL
SqlState: 28P01
MessageText: password authentication failed for user "postgres"
File: auth.c
Line: 328
Routine: auth_failed
При подключении к PostgreSQL с использованием psql
вместо моего приложения, Я могу запустить sudo -u postgres psql -U postgres
, и это успешно, а с другой стороны:
$ psql -U postgres
psql: FATAL: Peer authentication failed for user "postgres"
Поэтому я подумал, что следующее будет работать, но все равно не получится.
$ sudo -u postgres dotnet run
/usr/share/dotnet/sdk/3.1.100/NuGet.targets(528,5): error : Unable to obtain lock file access on '/tmp/NuGetScratch/lock/5d56c6a196882e7c1183dc543c1302123bf253ba' for operations on '/home/ethan/.nuget/NuGet/NuGet.Config'. This may mean that a different user or administator is holding this lock and that this process does not have permission to access it. If no other process is currently performing an operation on this file it may mean that an earlier NuGet process crashed and left an inaccessible lock file, in this case removing the file '/tmp/NuGetScratch/lock/5d56c6a196882e7c1183dc543c1302123bf253ba' will allow NuGet to continue.
The build failed. Fix the build errors and run again.
Почему это по-прежнему не удается?
Может ли мое приложение EF подключиться к PostgreSQL с использованием пользователя postgres?
Является ли пользователь postgres
по договоренности большим количеством привилегий?
Это хорошая идея, чтобы приложение получило доступ к PostgreSQL с пользователем postgres
?