postgresql을 Centos7에 설치해보겠당

 

근데 서버가 yum이나 library를 인터넷에서 받아오는 환경이 아니어서

tar 파일을 postgresql에서 받아주었다.

 

https://www.postgresql.org/ftp/source/v12.0/

 

PostgreSQL: File Browser

 

www.postgresql.org

 

 

1. tar 압축해제

tar xvfz postgresql-12.0.tar.gz

 

 

2. configure 파일 설정

sudo ./configure --prefix=/apim/data/postgresql/pgsql --without-readline --without-zlib

 

왠만하면 다 sudo권한으로 넣어서 명령어 실행시켜주었다.

 

--prefix 는 설치 디렉토리를 지정해주는 경로이다.

 

그리고 나는 서버에서 readline이랑 zlib이 없어서 빼고 설치하라고 나와서 without을 설정해주었다.

뒤에 두개 옵션은 빼도된다.

 

 

3. postgresql 설치

sudo make
sudo make install

 

 

4. DB 설치

 ./initdb -D /data

/data 라는 경로에 DB를 설치해 주었다.

원하는 경로를 입력 하면 된다.

/data라는 경로에 한 이유는 DB 마운트를 저 경로로 했기 때문이다.

 

 

5. DB 기동

./pg_ctl  start -D /data ( status, restart , stop)

 

start 대신해서 status를 입력하면 현재 상태

restart는 재기동

stop은 기동중지를 할 수 있다 ~_~

 

 

6. 외부 접속 허용

/data/postgresql.conf 에서

    1. listen_addresses = ‘localhost’ –> listen_addresses = ‘*’ 수정

data/pg_hba.conf 에서

  • host all all 0.0.0.0/0 password 추가 

 

7. psql 접속

./psql

 

8. 접속 한뒤 database 생성 및 user 생성

postgres=# CREATE DATABASE {DBname};
postgres=# CREATE USER {UserName};
postgres=# ALTER USER {UserName}  WITH PASSWORD '{Password}';

 

 

 

스키마 생성 및 삭제

Create schema {schemaName};

Drop schema {schemaName} cascade;

 

스키마 이름 변경 

ALTER SCHEMA schema_name RENAME TO new_schema_name;

 

스키마 소유자 변경

ALTER SCHEMA username OWNER TO new_username;

 

 

 

해당 database내의 schema 확인

\dn

 

현재 디비 계정및 role 정보

\du  

 

데이터베이스 접속

\connect {databaseName}

 

데이터베이스 목록조회 

\list  
\l

 

데이터베이스 목록 상세조회

\list+  
\l+

참고

https://lahuman.jabsiri.co.kr/173

 

[CentOS 6]Postgresql 소스 설치

Postgresql 소스 설치 정리 계정 생성 $> adduser postgres postgres 계정으로 로그인 $> su - postgres postgresql 소스 다운로드와 압축 해제 $> wget https://ftp.postgresql.org/pub/source/v9.5.7/postgresql..

lahuman.jabsiri.co.kr

http://blog.naver.com/hanccii/221701395102

 

PostgreSQL db, schema, user 권한 관리

PostgreSQL에서는 database 를 생성하면 default schema로 public 이라는 schema가 생성이 되며,backen...

blog.naver.com

 

 

'DEVELOP > DB' 카테고리의 다른 글

[postgreSql] pg_dump 하는 방법  (0) 2021.03.15
[DB]Isolation Level 알아보기  (0) 2020.07.19
[mySql] 계정 생성 및 권한 설정  (0) 2020.05.25
[MariaDB] general log 설정하기  (0) 2020.05.25
DB (mysql) 설정 변경  (0) 2020.03.13

ㅎㅎ

중요하지만 쵸큼은 헷갈리던 개념에 대해서

정리해보고자 한닷 '-'

 

정리해놓고 내가 다시보는게 중요하거덩여,,, RGRG,,


보통 4가지 레벨로 구분한다.

1. Read Uncomitted

2. Read Committed

3. Repeatable Read

4. Serializable 

 

한가지씩 정리해보고자 한닷 ^_^

사실 알면 간단하다..(자주하는말)

 

 

2. Read Uncommitted

transaction이 끝나지 않은 상황에서 다른 transaction이 변경한 내용에 대한 조회가 가능하다.

DB의 일관성 유지 할 수 없다.

 

다른 transaction에서 중간에 data를 변경하면 변경된 값 그대로 조회가 된다는 것이다.

 

dirty read 현상이 발생한다. transaction이 완료되지 않았는데 다른 transaction에서 볼 수 있는 현상이다.

 

 

2. Read Comitted

조회시, data에 대한 shared lock이 된다

commit이 된 data에 대해 조회가 된다. 하지만 어떠한 사용자가 어떠한 데이터를 변경하는 동안 

다른 transaction은 접근 할 수 없어 대기한다.

변경한 데이터가 commit되고 난 이후 접근 가능하다.

 

실제 테이블  값을 가져오는 것이 아니라 Undo 영역에 백업된 레코드에서 값을 가져온다.

 

 

3. Repeatable Read

transaction이 범위내에서는 조회한 데이터의 내용이 항상 동일함을 보장해준다.

 

Mysql에서는 transaction마다 트랜잭션 ID를 부여하여 트랜잭션id보다 작은 트랜잭션 번호에서 변경한것만 읽게된다.

 

undo 공간에 백업해두고 실제 레코드 값을 변경한다.

이러한 방식을 MVCC(Multi Version Concurrency Control)이라고 부른다.

 

insert시에는 값이 들어간건 보인다,,그래서 쓰기 잠금을 걸어야한다.

4. Serializable

모든 동작이 직렬화 되어 작동한다. Repeatable 와 다르게 insert를 하여도 작동하지 않는다.

성능 측면에서는 동시 처리성능이 가장 낮다.

거의 사용되지 않는다.

 

 

 

 

 

 

 

 

 

 

 

 

 


https://medium.com/@wonderful.dev/isolation-level-%EC%9D%B4%ED%95%B4%ED%95%98%EA%B8%B0-94e2c30cd8c9

 

Isolation level 이해하기

Isolation level이란 트랜잭션에서 일관성이 없는 데이터를 허용하는 수준을 이야기합니다.

medium.com

 

https://nesoy.github.io/articles/2019-05/Database-Transaction-isolation

 

트랜잭션의 격리 수준(isolation Level)이란?

 

nesoy.github.io

 

'DEVELOP > DB' 카테고리의 다른 글

[postgreSql] pg_dump 하는 방법  (0) 2021.03.15
[DB] postgreSql Centos7에 설치 및 설정하기  (0) 2020.08.24
[mySql] 계정 생성 및 권한 설정  (0) 2020.05.25
[MariaDB] general log 설정하기  (0) 2020.05.25
DB (mysql) 설정 변경  (0) 2020.03.13

인강을 듣고

Event라는 개념을 공부했다.

 

어렴풋이 - 

이해는 되는데 이걸 도대체 업무에서 어떻게 쓸 수 있을까?

란 의문점이 생겼다

 

도대체 Async로 하는거랑, 그냥 method 호출하는거랑

다른점이 뭐지? 이점이 뭐지???

 

그래서 서치해보았다~

 


1.  Application Event 란?

 

스프링 ApplicationEventPublisher는 스프링에서 이벤트 프로그래밍에 필요한 인터페이스를 제공한다. ApplicationContext 인터페이스에 이미 상속되어있어서 ApplicationContext의 구현체에서도 접근이 가능하다.

@Component
public class AppRunner implements ApplicationRunner {

    @Autowired
    ApplicationContext applicationContext;  

    @Override
    public void run(ApplicationArguments args) throws Exception {
        applicationContext.publishEvent(new MyEvent(this, 1)); // event에 접근 가능
    }
}

 

 

이벤트 수신 방법? @EventListener를 사용해서 빈의 메소드에 사용 

기본적으로는 synchronized 이다.

 

@Component
public class MyEventHandler {

@EventListener
// 반드시 다음 어노테이션을 써주어야 한다.
public void handle(MyEvent event){
	System.out.println("Event 수신 !!!" + event.getData());
	}
}

 

이벤트 순서를 정하고 싶다면 @Order 을 사용

비동기적으로 실행하고 싶다면 @Async을 사용하면 된다. 

 

 


https://engkimbs.tistory.com/718?category=767795

 

[Spring] ApplicationEventPublisher를 통한 스프링 이벤트 처리(ApplicationEventPublisher, Spring Event Processing)

| 스프링 ApplicationEventPublisher 스프링 ApplicationEventPublisher는 스프링에서 이벤트 프로그래밍에 필요한 인터페이스를 제공한다. ApplicationContext 인터페이스에 이미 상속되어있어서 ApplicationCon..

engkimbs.tistory.com

 

https://supawer0728.github.io/2018/03/24/spring-event/

 

Spring Event + Async + AOP 적용해보기

서론원래 글을 쓰기 위해 준비하던 내용은 Event를 강조하는 것이었는데, 준비를 하다 보니 Async와 AOP를 다 쓰게 되어버렸다. 이번 글에서는 하나의 transaction 안에서 많은 일을 처리하는 소스 코드

supawer0728.github.io

 

https://medium.com/@SlackBeck/spring-framework%EC%9D%98-applicationevent-%ED%99%9C%EC%9A%A9%EA%B8%B0-845fd2d29f32

 

Spring Framework의 ApplicationEvent 활용기

이 글은 필자가 현재 진행하고 있는 프로젝트에서 Event 식별하는 과정과 Spring Framework에서 제공하는 ApplicationEvent로 처리한 사례를 공유한다.

medium.com

 

 

업무를 하면서

 

잘쓰던 컴포넌트가 있었다.

엄청 여러 화면에서 범용적으로 쓰는 컴포넌트 였다 

 

그런데 어떤! 특정한 화면! 에서만

비지니스적인 요구사항에 의해 특정 부분

예를들어 버튼이나. 문구 등을 바꾸고 싶었다 

 

그렇다고 문구나 명명 한두개만 바꾸면 되는데

굳이 새로운 컴포넌트를 만들어야 할까???

 

아니.

 

근데 또 기존 컴포넌트를 이용하고 싶은데

기존 이 컴포넌트는 가져다 쓰는 화면에서는 영향도가 없었으면 좋겠어!

 

이런 요구사항이 있었다..

 

정말 완벽하게 딱 맞는 개념이 있다

 

그거슨,,, 바로

 

Slot

 

 


1. Slot 이란?

컴포넌트의 재사용성을 높이기 위해서 사용하는 기능이다.

 

 

2. 예시

 

<navigation-link>

<a
  v-bind:href="url"
  class="nav-link"
>
  <slot></slot>
</a>

 

<navigation-link>의 부모 

<navigation-link url="/profile">
  Your Profile
</navigation-link>

 

 

이런식으로 해주면 <slot></slot> 의 부분에

Your Profile이란 글씨가 나오게된다.

 

3. 컴파일 범위

 

여기서 중요하게 알아야 할 것은,

컴파일 범위이다 (Compilation Scope)

 

<navigation-link url="/profile">
  Logged in as {{ user.name }}
  <!-- user는 부모 컴포넌트에서 있기때문에 잘 표시 될것이닷! --!>
</navigation-link>

 

<navigation-link url="/profile">
  Clicking here will send you to: {{ url }}
  <!--
  url은 undefined로 나올 겁니다. 이 데이터는 <navigation-link>로
  넘어가지만 <navigation-link> 컴포넌트 안에 정의되어 있지는
  않으니까요.
  -->
</navigation-link>

 

부모 템플릿 안에 있는 것들은 부모 컴포넌트의 범위에 컴파일되고 자식 템플릿 안에 있는 것들은 자식 컴포넌트의 범위에 컴파일됩니다.

 

 

 

4. default 값 지정

 

다음과 같이 <submit-button> 컴포넌트에는 slot을 지정해주는데 

default로 Submit이라고 지정해 주었다.

<button type="submit">
  <slot>Submit</slot>
</button>

 

그래서 <submit-button>을 사용할때 따로 기입 하지 않으면 Submit이라고 나온다.

 

그런데 이렇게 Save 버튼을 만들고 싶으면 이렇게 만들어 주면 가능하다.

<submit-button>
  Save
</submit-button>

 

 

5. Named Slots

Vue 2.6.0 부터 지원

 

<base-layout> 컴포넌트다 여기 slot에는 각각 이름을 달아 주었다.

<div class="container">
  <header>
    <slot name="header"></slot>
  </header>
  <main>
    <slot></slot>
  </main>
  <footer>
    <slot name="footer"></slot>
  </footer>
</div>

 

 

이렇게 이름있는 slot을 가져다 쓸때에는

다음과같이 template 해주고 v-slot:slot이름 을 넣어주면 된다.

<base-layout>
  <template v-slot:header>
    <h1>Here might be a page title</h1>
  </template>

  <p>A paragraph for the main content.</p>
  <p>And another one.</p>

  <template v-slot:footer>
    <p>Here's some contact info</p>
  </template>
</base-layout>

 

다음도 가능 default 이름 넣어주기

 

<base-layout>
  <template v-slot:header>
    <h1>Here might be a page title</h1>
  </template>

  <template v-slot:default>
    <p>A paragraph for the main content.</p>
    <p>And another one.</p>
  </template>

  <template v-slot:footer>
    <p>Here's some contact info</p>
  </template>
</base-layout>

 

 

6. Scoped Slots

자식 컴포넌트에서만 접근 할 수 있는 데이터에서 슬롯에 필요한 내용을 가져올때 필요하다.

 

 

다음은 불가하다.

<span>
  <slot>{{ user.lastName }}</slot>
</span>

 

<current-user>
  {{ user.firstName }}
</current-user>

부모에서 user에 접근 할 수 없다.

<current-user>만 user에 접근 할 수 있다.

 

 

그런데 user의 정보가 필요해 그렇다면?

 

 

<span>
  <slot v-bind:user="user">
    {{ user.lastName }}
  </slot>
</span>

 

 

<current-user>
  <template v-slot:default="slotProps">
    {{ slotProps.user.firstName }}
  </template>
</current-user>

 

다음과 같이 부모 컴포넌트에서 가져올 slotProps를 지정해주고 

자식 컴포넌트에서는 v-bind로 연결해주면 된다.

 

 

 

 

 

 

 

 


참고

https://kr.vuejs.org/v2/guide/components-slots.html

 

슬롯(Slots) — Vue.js

Vue.js - 프로그레시브 자바스크립트 프레임워크

kr.vuejs.org

 

 

ㅎㅎ

일하면서 이런 이슈가 있었다.

 

Interceptor에서 데이터를 쌓고있는데

preHandle에서 왜 데이터가 두번 쌓이지?

 

라는 이슈가 있었다 

그래서 검색해보니 

 

https://www.logicbig.com/tutorials/spring-framework/spring-web-mvc/async-intercept.html

 

Spring MVC - Intercepting Async Requests using AsyncHandlerInterceptor

Spring MVC - Intercepting Async Requests using AsyncHandlerInterceptor [Updated: Feb 13, 2018, Created: Dec 9, 2016]

www.logicbig.com

 

이 링크를 찾았다

세상에 친절할 수가 

 

https://stackoverflow.com/questions/26995395/spring-mvc-interceptorhandler-called-twice-with-deferredresult

 

Spring MVC InterceptorHandler called twice with DeferredResult

When I am using custom HandlerInterceptor and my controller returns DeferredResult, the preHandle method of my custom interceptor called twice on each request. Consider a toy example. My custom

stackoverflow.com

 

 

즉 간단히 정리하자면 Async로 동작하면 Sync로 동작하는것과는  Interceptor가 다르게 동작한다.

ㅇ ㅏ , 물론 AsyncInterceptor를 사용했을때 말이다.

요 순서로 돌아간다고 생각하면 된다.

 

preHandle
afterConcurrentHandlingStarted
preHandle
postHandle
afterCompletion

 

그리고 첫번째 링크에 있는 그림을 보면 더 잘 이해가 간다.

다른 New Thread가 PreHandle 을 통과 하기 때문에 저 순서 인 것이다.

+ Recent posts