스프링 - Google OAuth2 value too long for type character varying(255) 문제 해결
작성 일자 : 2025년 04월 27일
발생한 문제
서비스 운영 도중 유저분께서 구글 로그인을 시도하였으나, Unauthorized 에러가 발생했다는 제보를 받았습니다.
해당 시간에 로그를 확인해보니 아래와 같은 에러가 발생했습니다.
2025-04-26T08:57:32.195Z ERROR 1 --- [lumo] [nio-8080-exec-3] o.h.engine.jdbc.spi.SqlExceptionHelper : ERROR: value too long for type character varying(255)
org.springframework.dao.DataIntegrityViolationException: could not execute statement [ERROR: value too long for type character varying(255)] [update social_accounts set created_at=?,deleted_at=?,email=?,social_display_name=?,social_profile_image_url=?,social_provider=?,social_provider_id=?,updated_at=? where id=?]; SQL [update social_accounts set created_at=?,deleted_at=?,email=?,social_display_name=?,social_profile_image_url=?,social_provider=?,social_provider_id=?,updated_at=? where id=?]
Caused by: org.hibernate.exception.DataException: could not execute statement [ERROR: value too long for type character varying(255)] [update social_accounts set created_at=?,deleted_at=?,email=?,social_display_name=?,social_profile_image_url=?,social_provider=?,social_provider_id=?,updated_at=? where id=?]
Caused by: org.postgresql.util.PSQLException: ERROR: value too long for type character varying(255)
원인
해당 에러는 구글 로그인 시도 시, social_profile_image_url
의 길이가 255를 초과하여 발생한 문제입니다. 구글 로그인 시, 구글에서 제공하는 프로필 이미지 URL이 255자를 초과하여 DB에 저장할 수 없었던 것입니다.
일반적으로 공개용 프로필 이미지 URL은 일반적으로 90 ~ 93자 정도로 훨씬 짧습니다. 하지만, 내부 공개 URL은 1027~1030자로 훨씬 더 길어질 수도 있습니다.
해결 방법
해결 방법은 간단합니다. DB의 social_profile_image_url
컬럼의 길이를 늘려주면 됩니다.
기존 social_accounts 테이블
create table social_accounts
(
created_at timestamp(6),
deleted_at timestamp(6),
id bigint not null,
updated_at timestamp(6),
email varchar(255) not null,
social_display_name varchar(255),
social_profile_image_url varchar(255),
social_provider varchar(255) not null,
social_provider_id varchar(255) not null,
primary key (id),
constraint fkxxxxxxxxxxxxxxxxxxxxxxx
foreign key (id) references users,
constraint social_accounts_social_provider_check
check ((social_provider)::text = ANY (ARRAY[('GOOGLE'::character varying)::text, ('NAVER'::character varying)::text, ('KAKAO'::character varying)::text, ('DISCORD'::character varying)::text, ('NONE'::character varying)::text]))
);
social_accounts 테이블 수정
alter table social_accounts
alter column social_profile_image_url type text;