[FIXED] Aufgrund des Authentifizierungstyps 10 kann keine Verbindung zur Postgres-DB hergestellt werden. 10 wird nicht unterstützt

Ausgabe

Ich habe mich kürzlich an Postgres versucht. Lokal installiert (PostgreSQL 13.0). Ein Maven-Projekt erstellt und Spring Data JPA verwendet, funktioniert einwandfrei. Während ich versucht habe, das Gradle-Projekt zu verwenden, kann ich keine Verbindung zur DB herstellen und erhalte weiterhin den folgenden Fehler.

org.postgresql.util.PSQLException: Der Authentifizierungstyp 10 wird nicht unterstützt. Vergewissern Sie sich, dass Sie die Datei pg_hba.conf so konfiguriert haben, dass sie die IP-Adresse oder das Subnetz des Clients enthält, und dass ein vom Treiber unterstütztes Authentifizierungsschema verwendet wird. at org.postgresql.core.v3.ConnectionFactoryImpl.doAuthentication(ConnectionFactoryImpl.java:614) ~[postgresql-42.1.4.jar:42.1.4] at org.postgresql.core.v3.ConnectionFactoryImpl.openConnectionImpl(ConnectionFactoryImpl.java: 222) ~[postgresql-42.1.4.jar:42.1.4] bei org.postgresql.core.ConnectionFactory.openConnection(ConnectionFactory.java:49) ~[postgresql-42.1.4.jar:42.1.4] bei org. postgresql.jdbc.PgConnection.(PgConnection.java:194) ~[postgresql-42.1.4.jar:42.1.4] at org.postgresql.Driver.makeConnection(Driver.java:450) ~[postgresql-42.1.4. jar:42.1.4] unter org.postgresql.Driver.connect (Driver.java:

Ich habe auch versucht, JDBCTemplate zu verwenden. Funktioniert nicht

Die Datei pg_hba.cfg, die sich auf diesen Beitrag bezieht, wurde geändert – Funktioniert nicht

Verwendet die veraltete Lib von – Funktioniert auch nicht.

Bitte schlagen Sie mir eine Lösung für dieses Problem vor.

Mein Code und Config:

    @Configuration
    public class DataSourceConfig {
    
        
        @Bean
        public DriverManagerDataSource getDataSource() {
            DriverManagerDataSource dataSourceBuilder = new DriverManagerDataSource();
            dataSourceBuilder.setDriverClassName("org.postgresql.Driver");
            dataSourceBuilder.setUrl("jdbc:postgresql://localhost:5432/postgres");
            dataSourceBuilder.setUsername("postgres");
            dataSourceBuilder.setPassword("root");
            return dataSourceBuilder;
        }
        
    }



@Component
public class CustomerOrderJDBCTemplate implements CustomerOrderDao{
    
    private DataSource dataSource;
    
    private JdbcTemplate jdbcTemplateObject;

    @Autowired
    ApplicationContext context;
    
    public void setDataSource() {
        //Getting Bean by Class
        DriverManagerDataSource dataSource = context.getBean(DriverManagerDataSource.class);
        this.dataSource = dataSource;
        this.jdbcTemplateObject = new JdbcTemplate(this.dataSource);
    }

@Override
    public Customer create(Customer customer) {
        setDataSource();
        String sql = "insert into CustomerOrder (customerType, customerPayment) values (?, ?)";
        //jdbcTemplateObject.update(sql, customerOrder.getCustomerOrderType(), customerOrder.getCustomerOrderPayment());
        
        KeyHolder holder = new GeneratedKeyHolder();
        jdbcTemplateObject.update(new PreparedStatementCreator() {
            @Override
            public PreparedStatement createPreparedStatement(Connection connection) throws SQLException {
                PreparedStatement ps = connection.prepareStatement(sql, Statement.RETURN_GENERATED_KEYS);
                ps.setString(1, customer.getType());
                ps.setString(2, customer.getPayment());
                return ps;
            }
        }, holder);

        long customerId = holder.getKey().longValue();
        customer.setCustomerID(customerOrderId);
        return customer;
        
    }

}

Abhängigkeiten

implementation('org.springframework.boot:spring-boot-starter-web')
    compile("org.springframework.boot:spring-boot-devtools")
    compile(group: 'org.postgresql', name: 'postgresql', version: '42.1.4')
    compile("org.springdoc:springdoc-openapi-ui:1.4.1")
    compile("org.springframework:spring-jdbc:5.2.5.RELEASE")

password_encryptionist so eingestellt:

postgres=# show password_encryption;
 password_encryption
---------------------
 scram-sha-256
(1 row)

Lösung

Ich habe ein ähnliches Problem gelöst, indem ich die folgenden Schritte in PostgreSQL Version 13 angewendet habe :

  1. Wechseln Sie password_encryptionzu md5einpostgresql.conf
Windows: C:\Program Files\PostgreSQL\13\data\postgresql.conf
GNU/Linux:           /etc/postgresql/13/main/postgresql.conf

enter image description here

  1. Wechseln Sie scram-sha-256zu md5einpg_hba.conf
Windows: C:\Program Files\PostgreSQL\13\data\pg_hba.conf
GNU/Linux:           /etc/postgresql/13/main/pg_hba.conf
host    all             all             0.0.0.0/0               md5

enter image description here

  1. Passwort ändern (dieses Wiederherstellungspasswort im md5-Format).

    Beispiel: ALTER ROLE postgres WITH PASSWORD 'root';

  2. Stellen Sie sicher, dass Sie einsteigen listen_addresses = '*', postgresql.confwenn Sie in einer Nicht-Produktionsumgebung arbeiten.


Beantwortet von –
Kishor K


Antwort geprüft von –
Jay B. (FixError Admin)

0 Shares:
Leave a Reply

Your email address will not be published. Required fields are marked *

You May Also Like