在本文中,我们将看到在 AWS RDS 中配置 Postgres 数据库实例的分步说明。

先决条件

要完成此学习,您将需要:

✓ AWS 账户(免费套餐)

如果您没有帐户,请访问https://aws.amazon.com并单击注册。

Amazon RDS 可用于多种数据库实例类型 - 针对内存、性能或 I/O 进行了优化

  • 亚马逊极光

  • PostgreSQL

  • MySQL

  • 玛丽亚数据库

  • 甲骨文

  • SQL 服务器

[Alt](https://res.cloudinary.com/practicaldev/image/fetch/s--jukJChDu--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev- to-uploads.s3.amazonaws.com/i/hsjtub5bd8surzi52jmd.png)

**EC2 上的 PostgreSQL **

您可以通过预置 EC2 实例和安装 Postgres 数据库来管理自己的数据库实例。

RDS 上的托管 PostgreSQL

托管 RDS 服务可以处理修补、备份、恢复、配置资源、可用性。

在本文中,我们将重点介绍使用托管服务 AWS RDS 来创建 PostgreSQL 数据库实例

通过 AWS 管理控制台使用 Amazon RDS 分步说明

第 1 步: 登录 AWS 管理控制台并使用关键字“RDS”进行搜索。您将被重定向到 RDS 主页

[Alt](https://res.cloudinary.com/practicaldev/image/fetch/s--h7ffTdH5--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev- to-uploads.s3.amazonaws.com/i/yvqb7xdmd0lyjb4kxduv.png)

第 2 步: 点击Create Database并选择Postgres

[Alt](https://res.cloudinary.com/practicaldev/image/fetch/s--DTJGy1hO--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev- to-uploads.s3.amazonaws.com/i/to7uwmzj9pqyay410e8k.png)

[Alt](https://res.cloudinary.com/practicaldev/image/fetch/s--9Osk1aOl--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev- to-uploads.s3.amazonaws.com/i/t1h1l9ie1lbks2bg9z4m.png)

步骤 3: 数据库实例设置

[Alt](https://res.cloudinary.com/practicaldev/image/fetch/s--DBdPofee--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev- to-uploads.s3.amazonaws.com/i/c86jcavbkdv90c4qq6qz.png)

第 4 步: 数据库实例大小和存储。对于免费层,您将获得“db.t2.micro”实例。

[Alt](https://res.cloudinary.com/practicaldev/image/fetch/s--ZKnJjthi--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev- to-uploads.s3.amazonaws.com/i/6v39rea8llv8ahp35xdh.png)

第 5 步: 实例连接

[Alt](https://res.cloudinary.com/practicaldev/image/fetch/s--K8moGlyB--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev- to-uploads.s3.amazonaws.com/i/wu4kgztzsr4ry1dx552c.png)

第 6 步: 附加配置

[Alt](https://res.cloudinary.com/practicaldev/image/fetch/s--HvVHxnlH--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev- to-uploads.s3.amazonaws.com/i/x85j1est4ntjhgdxfub8.png)

第 7 步: 备份配置

[Alt](https://res.cloudinary.com/practicaldev/image/fetch/s--N1mZ4zq3--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev- to-uploads.s3.amazonaws.com/i/8ognnjvismcsy27odfbk.png)

第 8 步: 单击 Create Database,您将看到资源创建进度。配置资源需要一些时间

[Alt](https://res.cloudinary.com/practicaldev/image/fetch/s--dY94sYMF--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev- to-uploads.s3.amazonaws.com/i/3vu5nydm0cstz9any0ux.png)

第 9 步: 要查看连接详细信息,请单击View Credential Details按钮

[Alt](https://res.cloudinary.com/practicaldev/image/fetch/s--ZUdonGJA--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev- to-uploads.s3.amazonaws.com/i/4kgyw4xykvt79xweow0l.png)

第 10 步: 从本地连接到 AWS RDS 实例并执行数据库脚本

[Alt](https://res.cloudinary.com/practicaldev/image/fetch/s--4GFqZL3T--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev- to-uploads.s3.amazonaws.com/i/yhmzg1kn0n6m3yvfkzb4.png)

使用 AWS 命令行界面

要从命令行控制和自动化 Amazon RDS 资源,请使用AWS 命令行界面 (CLI)

概括

您可以在下面的 github 项目中看到详细的实现并将 API 连接到 RDS 实例

GitHub 徽标sunilkumarmedium/CleanArchitectureApp

使用 Dotnet Core 3.1 WebApi 和 Angular 11 前端从头开始清洁架构应用程序设计

CleanArchitectureApp

使用 Dotnet Core 3.1 WebApi 和 Angular 11 前端从头开始清洁架构应用程序设计

MIT 许可证

技术

  • ASP.NET Core 3.1

  • NHibernate

  • 角 11

  • 角 CLI 11

  • 清洁架构

  • Swashbuckle.AspNetCore.Swagger

  • 设计模式:命令查询职责分离(CQRS)

  • 流利验证

  • WebAPI 全局异常中间件

  • 使用 JWT 令牌登录、注销和忘记密码

  • 支持 Microsoft Sql Server 和 Postgresql。

先决条件

1..Net core 3.1 SDK

2.Visual Studio 2019ORVSCodewithC#扩展

3.NodeJs(最新 LTS)

4.Microsoft SQL Server(可选:如果在开发过程中需要MS SQL server而不是Sqlite)

5.POSTGRESQL

配置

1.克隆repo:git clonehttps://github.com/sunilkumarmedium/CleanArchitectureApp.git

2.执行文件夹/sql/中可用的sql脚本

  • MSSQL 使用 CleanArchitectureDB.sql

  • POSTGRES 使用 CleanArchitectureDB-Postgres

3.更改appsettings.json中的数据库连接字符串

  • 路径:CleanArchitectureApp.WebApi/appsettings.Development.json 或 appsettings.json

*"DBProvider": "MSSQL" ,使用MSSQL连接 Microsoft SqlServer 或POSTGRES连接 PostgreSQL 数据库

*"ConnectionStrings": { "MSSQLConnection": "Data Source=DESKTOP-SUNILBO;Initial Catalog=CleanArchitectureDB;User ID=sa;Password=xxx;MultipleActiveResultSets=True", "PostgresConnection": "Server=127.0.0.1;Port=5432;Database=CleanArchitectureDB;User Id=postgres;Password=xxx;Timeout=30;TimeZone=UTC" }'

  1. kd...

在 GitHub 上查看

Logo

PostgreSQL社区为您提供最前沿的新闻资讯和知识内容

更多推荐