1. ホーム
  2. PostgreSQL

Postgresql+Springboot ymlの基本的な使い方

2022-02-26 03:35:20
<パス

I. Postgresql入門

PostgreSQLは、カリフォルニア大学コンピュータサイエンス学部が開発したPOSTGRES、バージョン4.2をベースにした非常にフル機能のフリーソフトウェアのオブジェクトリレーショナルデータベース管理システム(ORDBMS)です。POSTGRESの主要概念の多くは、商用Webデータベースで最近になって登場したものばかりです。PostgreSQLはほとんどの標準SQLをサポートし、複雑なクエリ、外部キー、トリガ、ビュー、トランザクション整合性、マルチバージョン並行性制御など、その他多くの最新機能を提供します。同様に、PostgreSQLは、新しいデータ型、関数、演算子、集約関数、インデックス作成方法、手続き言語などを追加することで、様々な方法で拡張することが可能です。さらに、ライセンスの柔軟性により、誰でも無料でPostgreSQLを使用、変更、配布することができます。

1.・PostgostreSQLは非常に安定しており、特にクラッシュなどには強いです。mysqlがコンピュータのクラッシュなどのシナリオでデータが失われることと比較すると、PGデータベースのこの点が優れている。

2., PostgostreSQL は Mysql よりも多くのデータ型をサポートしています。

3. PostgostreSQL は sql を使用してプログラムすることができます。

plproxyはステートメントレベルのミラーリングやシャーディングを、slonyはフィールドレベルの同期を、standbyはWALファイルレベルやストリーミング読み書き分離クラスタを構築できる。同期頻度やクラスタポリシーは簡単に調整でき、運用は非常にシンプルだ。

5.・PostgreSQLの関数と条件付きインデックスの利用機能

6., PGのTEXT型に直接アクセス可能、SQL構文内蔵の正規表現、インデックス、全文検索。PGを使用する場合は、ドキュメントデータベースを保存することができます。

7., PostgreSQLのパフォーマンスは非常に強力で、高度に同時進行する読み書きのシナリオでもPostgreSQLのパフォーマンス指標はトップを維持できます。同じシナリオで大きく落ち込むMySQLと比較して(mysql 5.5以降、エンタープライズ版にはかなり改善できるプラグインがありますが、お金がかかります)、PostgreSQLのパフォーマンス指標は高いです。

II. Postgresql+Springbootの基本的なymlの使用法

1. Mavenのインポート

        <dependency>
            <groupId>org.postgresql</groupId>
            <artifactId>postgresql</artifactId>
            <scope>runtime</scope>
        </dependency>

spring:
  datasource:

    url: jdbc:postgresql://localhost:5432/postgres # url: jdbc:mysql://localhost:3306/tis?serverTimezone=UTC&useUnicode=true& characterEncoding=utf8&useSSL=false
    username: postgres
    password: 123456
    driverClassName: org.postgresql.
  jackson:
    time-zone: GMT+8
  jpa:
    properties:
      hibernate:
        show_sql: true
        format_sql: true
        ddl-auto: update #The framework will automatically create or update the table structure for us

  rabbitmq:
    host: 192.168.90.205
    port: 5672
    username: admin
    password: admin
    virtual-host: /


2. 設定ファイルymlの記述

package com.supcon.oms.entity;

import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import lombok.Data;

import javax.persistence.*;
import java.io.Serializable;

/**
 * @author: zhaoxu
 * @date: 2020/9/8 20:43
 */
@Data
@Entity
@Table(name = "t_tank", schema = "public", catalog = "")
@JsonIgnoreProperties(ignoreUnknown = true)
public class TTankEntity implements Serializable {
    private static final long serialVersionUID = 4718371560086576837L;
    @Id
    @Column(name="tank_id")
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    private Integer tankId;
    @Basic
    @Column(name = "tank_no", nullable = false, length = 255)
    private String tankNo;

    @Basic
    @Column(name = "equipment_type", nullable = true, length = 255)
    private String equipmentType;
    @Basic
    @Column(name = "tank_name", nullable = true, length = 255)
    private String tankName;
    @Basic
    @Column(name = "tank_description", nullable = true, length = 1000)
    private String tankDescription;
    @Basic
    @Column(name = "equipment_status", nullable = true, length = 255)
    private String equipmentStatus;
    @Basic
    @Column(name = "tank_keepwarm", nullable = true, length = 100)
    private String tankKeepwarm;
    @Basic
    @Column(name = "tank_status", nullable = true, length = 255)
    private String tankStatus;
    @Basic
    @Column(name = "tank_farmid", nullable = true, length = 255)
    private String tankFarmid;
    @Basic
    @Column(name = "tank_type", nullable = true, length = 255)
    private String tankType;
    @Basic
    @Column(name = "tank_diameter", nullable = true, precision = 0)
    private Double tankDiameter;
    @Basic
    @Column(name = "tank_height", nullable = true, precision = 0)
    private Double tankHeight;
    @Basic
    @Column(name = "tank_capacity_standard", nullable = true, precision = 0)
    private Double tankCapacityStandard;
    @Basic
    @Column(name = "liquid_level_temperature", nullable = true, precision = 0)
    private Double liquidLevelTemperature;
    @Basic
    @Column(name = "tank_capacity_safe", nullable = true, precision = 0)
    private Double tankCapacitySafe;
    @Basic
    @Column(name = "calculate_type", nullable = true, length = 255)
    private String calculateType;
    @Basic
    @Column(name = "working_level_min", nullable = true, precision = 0)
    private Double workingLevelMin;
    @Basic
    @Column(name = "working_level_max", nullable = true, precision = 0)
    private Double workingLevelMax; @Basic
    @Column(name = "nominal_volume", nullable = true, precision = 0)
    private Double nominalVolume;
    @Basic
    @Column(name = "thermal_expansion_system", nullable = true, length = 255)
    private String thermalExpansionSystem;
    @Basic
    @Column(name = "floating_point_quality", nullable = true, length = 255)
    private String floatingPointQuality;
    @Basic
    @Column(name = "level_change_dead", nullable = true, length = 100)
    private String levelChangeDead;
    @Basic
    @Column(name = "alarm_events", nullable = true, length = 255)
    private String alarmEvents;
    @Basic
    @Column(name = "tank_capacity_now", nullable = true, precision = 0)
    private Double tankCapacityNow;
    @Basic
    @Column(name = "tank_quality", nullable = true, precision = 0)
    private Double tankQuality;
    @Basic
    @Column(name = "tank_temperature", nullable = true, precision = 0)
    private Double tankTemperature;
    @Basic
    @Column(name = "tank_pressure", nullable = true, precision = 0)
    private Double tankPressure;
    @Basic
    @Column(name = "flow_speed", nullable = true, precision = 0)
    private Double flowSpeed;
    @Basic
    @Column(name = "flow_amount", nullable = true, precision = 0)
    private Double flowAmount;
    @Basic
    @Column(name = "remaining_space", nullable = true, precision = 0)
    private Double remainingSpace;
    @Basic
    @Column(name = "vcf", nullable = true, precision = 0)
    private Double vcf;
    @Basic
    @Column(name = "liquid_level_status", nullable = true, length = 255)
    private String liquidLevelStatus;
    @Basic
    @Column(name = "net_standard_volume", nullable = true, precision = 0)
    private Double netStandardVolume;
    @Basic
    @Column(name = "water_bottom_volume", nullable = true, precision = 0)
    private Double waterBottomVolume;
    @Basic
    @Column(name = "tank_flow_inout", nullable = true, precision = 0)
    private Double tankFlowInout;
    @Basic
    @Column(name = "usable_volume", nullable = true, precision = 0)
    private Double usableVolume;
    @Basic
    @Column(name = "standard_quality_sum", nullable = true, precision = 0)
    private Double standardQualitySum;
    @Basic
    @Column(name = "standard_qual

3. Entityエンティティクラスを記述する

package com.supcon.oms.entity;

import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import lombok.Data;

import javax.persistence.*;
import java.io.Serializable;

/**
 * @author: zhaoxu
 * @date: 2020/9/8 20:43
 */
@Data
@Entity
@Table(name = "t_tank", schema = "public", catalog = "")
@JsonIgnoreProperties(ignoreUnknown = true)
public class TTankEntity implements Serializable {
    private static final long serialVersionUID = 4718371560086576837L;
    @Id
    @Column(name="tank_id")
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    private Integer tankId;
    @Basic
    @Column(name = "tank_no", nullable = false, length = 255)
    private String tankNo;

    @Basic
    @Column(name = "equipment_type", nullable = true, length = 255)
    private String equipmentType;
    @Basic
    @Column(name = "tank_name", nullable = true, length = 255)
    private String tankName;
    @Basic
    @Column(name = "tank_description", nullable = true, length = 1000)
    private String tankDescription;
    @Basic
    @Column(name = "equipment_status", nullable = true, length = 255)
    private String equipmentStatus;
    @Basic
    @Column(name = "tank_keepwarm", nullable = true, length = 100)
    private String tankKeepwarm;
    @Basic
    @Column(name = "tank_status", nullable = true, length = 255)
    private String tankStatus;
    @Basic
    @Column(name = "tank_farmid", nullable = true, length = 255)
    private String tankFarmid;
    @Basic
    @Column(name = "tank_type", nullable = true, length = 255)
    private String tankType;
    @Basic
    @Column(name = "tank_diameter", nullable = true, precision = 0)
    private Double tankDiameter;
    @Basic
    @Column(name = "tank_height", nullable = true, precision = 0)
    private Double tankHeight;
    @Basic
    @Column(name = "tank_capacity_standard", nullable = true, precision = 0)
    private Double tankCapacityStandard;
    @Basic
    @Column(name = "liquid_level_temperature", nullable = true, precision = 0)
    private Double liquidLevelTemperature;
    @Basic
    @Column(name = "tank_capacity_safe", nullable = true, precision = 0)
    private Double tankCapacitySafe;
    @Basic
    @Column(name = "calculate_type", nullable = true, length = 255)
    private String calculateType;
    @Basic
    @Column(name = "working_level_min", nullable = true, precision = 0)
    private Double workingLevelMin;
    @Basic
    @Column(name = "working_level_max", nullable = true, precision = 0)
    private Double workingLevelMax; @Basic
    @Column(name = "nominal_volume", nullable = true, precision = 0)
    private Double nominalVolume;
    @Basic
    @Column(name = "thermal_expansion_system", nullable = true, length = 255)
    private String thermalExpansionSystem;
    @Basic
    @Column(name = "floating_point_quality", nullable = true, length = 255)
    private String floatingPointQuality;
    @Basic
    @Column(name = "level_change_dead", nullable = true, length = 100)
    private String levelChangeDead;
    @Basic
    @Column(name = "alarm_events", nullable = true, length = 255)
    private String alarmEvents;
    @Basic
    @Column(name = "tank_capacity_now", nullable = true, precision = 0)
    private Double tankCapacityNow;
    @Basic
    @Column(name = "tank_quality", nullable = true, precision = 0)
    private Double tankQuality;
    @Basic
    @Column(name = "tank_temperature", nullable = true, precision = 0)
    private Double tankTemperature;
    @Basic
    @Column(name = "tank_pressure", nullable = true, precision = 0)
    private Double tankPressure;
    @Basic
    @Column(name = "flow_speed", nullable = true, precision = 0)
    private Double flowSpeed;
    @Basic
    @Column(name = "flow_amount", nullable = true, precision = 0)
    private Double flowAmount;
    @Basic
    @Column(name = "remaining_space", nullable = true, precision = 0)
    private Double remainingSpace;
    @Basic
    @Column(name = "vcf", nullable = true, precision = 0)
    private Double vcf;
    @Basic
    @Column(name = "liquid_level_status", nullable = true, length = 255)
    private String liquidLevelStatus;
    @Basic
    @Column(name = "net_standard_volume", nullable = true, precision = 0)
    private Double netStandardVolume;
    @Basic
    @Column(name = "water_bottom_volume", nullable = true, precision = 0)
    private Double waterBottomVolume;
    @Basic
    @Column(name = "tank_flow_inout", nullable = true, precision = 0)
    private Double tankFlowInout;
    @Basic
    @Column(name = "usable_volume", nullable = true, precision = 0)
    private Double usableVolume;
    @Basic
    @Column(name = "standard_quality_sum", nullable = true, precision = 0)
    private Double standardQualitySum;
    @Basic
    @Column(name = "standard_qual

あとは通常のフレームワークで書かれており、基本的にmysqlの使い方と同じです